layout_weight with buttons and text views in table row

后端 未结 1 1678
一个人的身影
一个人的身影 2021-01-16 10:59

I am trying to make four rows of three buttons each, and at the bottom of the buttons are two text views. I would like for them all to be spaced evenly but they aren\'t and

相关标签:
1条回答
  • 2021-01-16 11:30

    Ok so to help out with this add android:stretchColumns="0,1,2,3" in your Table Layout which would make buttons even sized.

    Secondly add a android:layout_span="2" to both of your text views.

    Heres you a final code:

    <!-- NOTICE STRETCHCOLUMNS ATTRIBUTE-->
    <TableLayout android:id="@+id/TableLayout01"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:stretchColumns="0,1,2,3"
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    >
    .
    .
    .
    
    .
    .
    <!-- NOTICE LAYOUT_SPAN ATTRIBUTE-->
    <TextView android:text="@+id/TextView01" 
        android:layout_weight="1" 
        android:id="@+id/TextView01"
        android:layout_span="2"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"></TextView>
    
    <TextView android:text="@+id/TextView02"
        android:layout_weight="1" 
        android:id="@+id/TextView02" 
        android:layout_span="2"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"></TextView>
    

    If you are setting the text size programmatically to make your TextViews evenly spaced, its not needed when you have android:layout_span set.

    0 讨论(0)
提交回复
热议问题