2016-01-13 71 views
-1

我创建了一块电路板,并将其与天文台和按钮一起放入LinearLayout(垂直)中。我给下面的权重为他们每个人:如何让TableLayout垂直占用所有可用空间?

局:5 天文台:10 按钮:10

的天文钟钮,其正确的地方,但是董事会不占用你所有的空间你身高。有人帮助我吗?

Java类:

tableLayout = (TableLayout) findViewById(R.id.tabuleiro); 
 

 
     GradientDrawable gd = new GradientDrawable(); 
 
     gd.setColor(azul); 
 
     gd.setStroke(1, preto); 
 

 
     final GradientDrawable gd2 = new GradientDrawable(); 
 
     gd2.setStroke(1, 0xFF000000); 
 
     gd2.setColor(Color.RED); 
 

 
     TableLayout.LayoutParams tableParams = new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT,TableLayout.LayoutParams.MATCH_PARENT); 
 
     TableRow.LayoutParams rowParams = new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.MATCH_PARENT); 
 

 
     for (int i = 0; i < 10; i++){ 
 

 
      tableRow = new TableRow(this); 
 
      tableRow.setLayoutParams(rowParams); 
 

 
      for (int j = 0; j < 10; j++){ 
 

 
       textView = new TextView(this); 
 
       textView.setLayoutParams(rowParams); 
 
       textView.setBackgroundDrawable(gd); 
 
       textView.setTag(String.valueOf(i + "." + j)); 
 

 
       textView.setOnClickListener(new View.OnClickListener() { 
 

 
        @Override 
 
        public void onClick(View v) { 
 

 
         v.setBackgroundDrawable(gd2); 
 
        } 
 
       }); 
 

 
       tableRow.addView(textView, rowParams); 
 
      } 
 

 
      tableLayout.addView(tableRow, tableParams); 
 
     }

XML:

<LinearLayout 
 
    xmlns:android="http://schemas.android.com/apk/res/android" 
 
    android:layout_width="match_parent" 
 
    android:layout_height="match_parent" 
 
    android:id="@+id/lnl" 
 
    android:background="#a9c3ff" 
 
    android:orientation="vertical"> 
 

 
    <LinearLayout 
 
     android:orientation="vertical" 
 
     android:layout_width="match_parent" 
 
     android:layout_height="match_parent" 
 
     android:layout_gravity="center_vertical" 
 
     android:gravity="center_vertical|center_horizontal" 
 
     android:layout_marginTop="40dp" 
 
     android:id="@+id/linearLayout2"> 
 

 
     <TableLayout 
 
      xmlns:android="http://schemas.android.com/apk/res/android" 
 
      android:layout_width="match_parent" 
 
      android:layout_height="match_parent" 
 
      android:stretchColumns="*" 
 
      android:id="@+id/tabuleiro" 
 
      android:layout_gravity="center_vertical" 
 
      android:layout_weight="5"> 
 

 
     </TableLayout> 
 

 
     <Chronometer 
 
      android:layout_width="match_parent" 
 
      android:layout_height="match_parent" 
 
      android:id="@+id/chrono" 
 
      android:layout_gravity="center_horizontal" 
 
      android:textSize="40dp" 
 
      android:layout_weight="10" 
 
      android:gravity="center" /> 
 

 
     <Button 
 
      android:layout_width="match_parent" 
 
      android:layout_height="match_parent" 
 
      android:text="@string/btn_voltar" 
 
      android:id="@+id/btn_voltar" 
 
      android:hyphenationFrequency="normal" 
 
      android:layout_weight="10" /> 
 

 
    </LinearLayout> 
 

 
</LinearLayout>

IMAGE OF APP

回答

0

尝试以下操作:

<LinearLayout 
 
    xmlns:android="http://schemas.android.com/apk/res/android" 
 
    android:layout_width="match_parent" 
 
    android:layout_height="match_parent" 
 
    android:id="@+id/lnl" 
 
    android:background="#a9c3ff" 
 
    android:orientation="vertical"> 
 

 
    <LinearLayout 
 
     android:orientation="vertical" 
 
     android:layout_width="match_parent" 
 
     android:layout_height="match_parent" 
 
     android:layout_gravity="center_vertical" 
 
     android:gravity="center_vertical|center_horizontal" 
 
     android:layout_marginTop="40dp" 
 
     android:id="@+id/linearLayout2"> 
 

 
     <TableLayout 
 
      xmlns:android="http://schemas.android.com/apk/res/android" 
 
      android:layout_width="match_parent" 
 
      android:layout_height="0dp" 
 
      android:layout_weight="1" 
 
      android:stretchColumns="*" 
 
      android:id="@+id/tabuleiro" 
 
      android:layout_gravity="center_vertical" 
 
      android:layout_weight="5"> 
 

 
     </TableLayout> 
 

 
     <Chronometer 
 
      android:layout_width="match_parent" 
 
      android:layout_height="wrap_content" 
 
      android:id="@+id/chrono" 
 
      android:layout_gravity="center_horizontal" 
 
      android:textSize="40dp" 
 
      android:layout_weight="10" 
 
      android:gravity="center" /> 
 

 
     <Button 
 
      android:layout_width="match_parent" 
 
      android:layout_height="wrap_content" 
 
      android:text="@string/btn_voltar" 
 
      android:id="@+id/btn_voltar" 
 
      android:hyphenationFrequency="normal" 
 
      android:layout_weight="10" /> 
 

 
    </LinearLayout> 
 

 
</LinearLayout>

相关问题