2011-10-13 6 views
2

여기에 문제가 있습니다.Android TableLayout은 셀 내용을 확장합니다.

일부 ImageButton을 포함하는 TableLayout을 만들고 있습니다.

각 행에는 3 개의 ImageButton이 있지만 너비가 테이블의 너비와 같지 않습니다. 높이도 마찬가지입니다.

내가 원하는 모두는 ImageButtons가에있는 세포 내에서 센터입니다.

auto:StretchColumns="*" 

가 ImageButtons (셀 데이터)를 뻗어, 심지어는 XML 파일의 크기를 지정 .

또한 행에 대해 동일한 작업을 수행 할 수있는 옵션이 있습니까?

셀의 여백 계산이 자동으로 비슷합니다.

답변

2

ImageButton에 대해 android:layout_gravity="center"을 설정해 보셨습니까?

또는이 같은 LinearLayoutImageButton 포장 수 : 테이블 레이아웃의

<LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent"> 
    <ImageButton android:layout_gravity="center" ...other attributes... /> 
</LinearLayout> 
+0

예, 아무 효과가 없습니다. 난 당신이 그것을 불필요하게 무거운 (많이는 아니지만, 그것을 할 것입니다 작동시킬 수있는 말을하는 동안 다른 접근 방식을 시도하고있다)하지만 – ikromm

+0

당신은 레이아웃 파일이나 그것의 샘플을 게시해볼 수 있습니까? – kaspermoerch

+0

필요 없음. 그것은 조금 더 무겁더라도 정확하게 작동합니다. 건배 :) – ikromm

1

아이들은 TableRow 될 필요가 없습니다. 테이블 레이아웃은 LinearLayout, TextView, ImageButton 등 모든 유형의 자식을 지원합니다.

이미지 버튼을 TableRow에 래핑하지 마십시오. 그것을 행으로 삽입하십시오.

<TableRow> 
    <TextView 
     android:id="@+id/tv1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Example Table Row" /> 
</TableRow> 

<ImageButton 
    android:id="@+id/ib1" 
    android:layout_width="fill_parent" <---! The Parent Is The Table Layout !---> 
    android:layout_height="wrap_content" 
    android:background="@drawable/coolBGImage" /> 

<TableRow> 
BLAH BLAH BLAH 
</TableRow> 

는 버튼이 균일하게 열을 나눌 수 있도록 동일한 중량으로 다음 두 이미지 버튼을 추가 android:orientation="horizontal"

</TableRow> 

<LinearLayout 
    android:id="@+id/LL1" 
    android:layout_width="fill_parent" <---! The Parent is the TableLayout !---> 
    android:layout_height="wrap_content" 
    android:orientation="horizontal"> 

     <ImageButton 
      android:id="@+id/IB1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:background="@drawable/coolBGImage1" 
      android:weight="1" /> 

사용할 하나 개의 행에있는 LinearLayout 3 ImageButtons 넣어.

</LinearLayout> 
관련 문제