2012-06-30 2 views
0

Я новичок в разработке Android.
У меня есть активность, в которой я хотел бы установить несколько кнопок в двух строках таблицы. но в настоящее время они используют лишь малую часть его
Вот XML для макета для этой деятельности:
Как заставить ячейки таблицы использовать всю высоту экрана в TableLayout?

<?xml version="1.0" encoding="utf-8"?> 
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/TableLayout1" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 


    <TableRow 
     android:id="@+id/tableRow1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" > 

     <Button 
      android:id="@+id/button1" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="Button" /> 

     <Button 
      android:id="@+id/button2" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="Button" /> 

     <Button 
      android:id="@+id/button3" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="Button" /> 
    </TableRow> 


    <TableRow 
     android:id="@+id/tableRow2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" > 

    </TableRow> 

    <TableRow 
     android:id="@+id/tableRow3" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" > 
    </TableRow> 

</TableLayout> 

Спасибо за любую помощь!

ответ

1

пытаются использовать Android: layout_weight = "1" в строке таблицы

<TableRow 
     android:id="@+id/tableRow1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="1"> 

увидеть этот

<?xml version="1.0" encoding="utf-8"?> 
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/TableLayout1" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 


    <TableRow 
     android:id="@+id/tableRow1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:background="#ffff0000"> 

     <Button 
      android:id="@+id/button1" 
      android:layout_width="0dp" 
      android:layout_height="fill_parent" 
      android:layout_weight="1" 
      android:text="Button" /> 

     <Button 
      android:id="@+id/button2" 
      android:layout_width="0dp" 
      android:layout_height="fill_parent" 
      android:layout_weight="1" 
      android:text="Button" /> 

     <Button 
      android:id="@+id/button3" 
      android:layout_width="0dp" 
      android:layout_height="fill_parent" 
      android:layout_weight="1" 
      android:text="Button" /> 
    </TableRow> 


    <TableRow 
     android:id="@+id/tableRow2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
      android:background="#ff00ff00"> 

    </TableRow> 

    <TableRow 
     android:id="@+id/tableRow3" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
      android:background="#ff00ff"> 
    </TableRow> 

</TableLayout> 

enter image description here

+0

это не help.They до сих пор не занимают всю высоту экрана. –

+0

Спасибо за ваши усилия, вам также нужно установить, вероятно, для каждой кнопки layout_height = "0dp", чтобы они занимали одну треть высоты экрана, если у вас 3 строки. –

+0

извините, но хотите ли вы, чтобы все три строки заполнили размер экрана не только одним? –

0

его, как это ....

  1. Либо goto инструмент GUI для редактирования свойств XML в Eclipse и установки свойства макета layout weight to 1.

    ИЛИ Гото страницу XML, и выполните следующие действия в таблице строки android:layout_weight="1" android:layout_width="wrap_content" и android:layout_height="wrap_content"

+0

Как насчет layout_width и layout_height макета? мне нужно установить их на что-то еще или сохранить как fill_parent? –

+0

android: layout_width = "wrap_content" android: layout_height = "wrap_content" я не упоминал их, думая, что это совершенно очевидно, что вы его реализуете ... извините за это –

Смежные вопросы