2010-12-31 5 views
1

각각 3 개의 버튼으로 4 개의 행을 만들려고하고 있으며 버튼 하단에는 2 개의 텍스트보기가 있습니다. 나는 그들 모두가 균등하게 간격을두기를 원하지만, 그렇지 않다. 왜 그런지 모르겠다.layout_weight 테이블 행의 버튼 및 텍스트보기

다음은 내 main.xml 파일의 코드입니다. 내 프로그램을 실행하면

TextView t = (TextView)findViewById(R.id.TextView01); 
TextView t2 = (TextView)findViewById(R.id.TextView02); 
t.setTextSize(24); 
t2.setTextSize(24); 

내가 얻을 :

<?xml version="1.0" encoding="utf-8"?> 

<TableLayout android:id="@+id/TableLayout01" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    xmlns:android="http://schemas.android.com/apk/res/android"> 

<TableRow 

    android:id="@+id/TableRow01" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 

<Button android:onClick="button_click" 
    android:layout_weight="1" 
    android:id="@+id/Button01" 
    android:text="@string/str_1"/> 

<Button android:onClick="button_click" 
    android:layout_weight="1" 
    android:id="@+id/Button02" 
    android:text="@string/str_2"/> 

<Button android:onClick="button_click" 
    android:layout_weight="1" 
    android:id="@+id/Button03" 
    android:text="@string/str_3"/> 

<Button android:onClick="button_click" 
    android:layout_weight="1" 
    android:id="@+id/Button04" 
    android:text="@string/str_4"/> 

</TableRow> 

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

<Button android:onClick="button_click" 
    android:layout_weight="1" 
    android:id="@+id/Button05" 
    android:text="@+string/str_5"/> 

<Button android:onClick="button_click" 
    android:layout_weight="1" 
    android:id="@+id/Button06" 
    android:text="@+string/str_6"/> 

<Button android:onClick="button_click" 
    android:layout_weight="1" 
    android:id="@+id/Button07" 
    android:text="@+string/str_7"/> 

<Button android:onClick="button_click" 
    android:layout_weight="1" 
    android:id="@+id/Button08" 
    android:text="@+string/str_8"/> 

</TableRow> 

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

<Button android:onClick="button_click" 
    android:layout_weight="1" 
    android:id="@+id/Button09" 
    android:text="@+string/str_9"/> 

<Button android:onClick="button_click" 
    android:layout_weight="1" 
    android:id="@+id/Button10" 
    android:text="@+string/str_10"/> 

<Button android:onClick="button_click" 
    android:layout_weight="1" 
    android:id="@+id/Button11" 
    android:text="@+string/str_11"/> 

<Button android:onClick="button_click" 
    android:layout_weight="1" 
    android:id="@+id/Button12" 
    android:text="@+string/str_12"/> 

</TableRow> 

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

<TextView android:text="@+id/TextView01" 
    android:layout_weight="1" 
    android:id="@+id/TextView01" 
    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_width="wrap_content" 
    android:layout_height="wrap_content"></TextView> 

</TableRow> 

</TableLayout> 

내 텍스트 뷰는 다음과 같은 코드가

alt text

답변

3

너무 좋아에 android:stretchColumns="0,1,2,3"를 추가이 함께 도움을 당신의 버튼 레이아웃을 조정하는 표 레이아웃.

두 번째로 두 텍스트보기 모두에 android:layout_span="2"을 추가하십시오.

Heres는 당신 최종 코드 :

<!-- 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> 

프로그래밍 당신의 TextViews 균등 당신이 android:layout_span 세트가있을 때 그 필요하지, 간격 수 있도록 텍스트 크기를 설정하는 경우.

+0

이것은 아름답게 작동했습니다. 정말 고마워요! – valon

관련 문제