2010-08-20 4 views
0

Je me bats avec l'interface utilisateur Android pour essayer de créer une mise en page de tableau comportant deux lignes avec deux boutons dans chaque rangée. Je veux que les boutons occupent chacun 50% de l'espace de la rangée. Cependant, peu importe ce que je définis les layout_width et layout_height, j'ai toujours deux boutons skinny dans chaque rangée.Baffle de mise en page du tableau

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    > 
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="horizontal" 
    android:id="@+id/tablelayout" > 
<TableRow> 
<Button 
    android:id="@+id/btn_one" 
    android:tag="1" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:text=""/> 
<Button 
    android:id="@+id/btn_two" 
    android:tag="2" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:text="" 
    android:padding="0px"/> 
</TableRow> 
<TableRow> 
<Button 
    android:id="@+id/btn_three" 
    android:tag="3" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:text=""/> 
<Button 
    android:id="@+id/btn_four" 
    android:tag="4" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:text=""/> 
</TableRow> 
</TableLayout> 
</LinearLayout> 

Répondre

1

La réponse est d'utiliser le paramètre magic layout_weight.

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    > 
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="horizontal" 
    android:id="@+id/tablelayout" > 
<TableRow 
    android:layout_weight="1"> 
<Button 
    android:id="@+id/btn_one" 
    android:tag="1" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_weight="1" 
    android:text=""/> 
<Button 
    android:id="@+id/btn_two" 
    android:tag="2" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_weight="1" 
    android:text="" 
    android:padding="0px"/> 
</TableRow> 
<TableRow 
    android:layout_weight="1" 
> 
<Button 
    android:id="@+id/btn_three" 
    android:tag="3" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_weight="1" 
    android:text=""/> 
<Button 
    android:id="@+id/btn_four" 
    android:tag="4" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_weight="1" 
    android:text=""/> 
</TableRow> 
</TableLayout> 
</LinearLayout>