2014-07-04 2 views
0

안드로이드에서 TableLayout을 배우고 있으며 다음 레이아웃에서 약간의 불일치가 발생합니다. 나는 두번째 줄에 3 개의 버튼과 2 개의 버튼을 가지고있다. 다음은 코드입니다 : 테이블 레이아웃의 버튼 너비

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    > 

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

    <Button 
     android:id="@+id/button1" 
     android:layout_height="wrap_content" 
     android:text="this Button is big" 
     android:layout_weight="1" /> 

    <Button 
     android:id="@+id/button3" 
     android:layout_height="wrap_content" 
     android:text="button" 
     android:layout_weight="1" /> 

    </TableRow> 

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

     <Button 
      android:id="@+id/button4" 
      android:layout_height="wrap_content" 
      android:text="Button" 
      android:layout_weight="1" /> 

     <Button 
      android:id="@+id/button5" 
      android:layout_height="wrap_content" 
      android:text="Button" 
      android:layout_weight="1" /> 

    </TableRow> 

</TableLayout> 

가운데 버튼의 텍스트가 큰

이 두 버튼은 자신의 체중이 동일하고 동등한 inspite오고되지 않습니다. 그러나 마지막 버튼의 텍스트가 증가하면 버튼이 동일 해집니다. 친절 두 이미지가 enter image description here enter image description here 감사

있는 가운데 텍스트가 부착 더 큰 경우 버튼이 동일 오지 않을 이유 업데이트

답변

0

무게를 유지하면서, match_parent 각 버튼의 layout_width을 설정해보십시오 = 1 match_parent은 말할 것 버튼은 가능한 한 많은 공간을 소비하는 반면, 가중치는 공간이 분배되는 방법을 결정합니다. 또한 버튼 텍스트를 잘리는 방법 (예 : 단일 줄, 줄임표)을 지정해야합니다.

+0

tablelayout의 하위 항목에 너비를 지정하지 않아도됩니다. https://developer.android.com/ reference/android/widget/TableLayout.html – user2779311

관련 문제