2015-01-11 3 views
1

중앙 수 없습니다 난 다음 한 레이아웃 코드 :안드로이드 표 행, 텍스트

enter image description here

어떻게 해결할 수 :

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

    <!-- APP NAME --> 
    <TableRow 
     android:id="@+id/table_heading" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:background="#2d9adf" 
     android:gravity="center_vertical" 
     android:padding="5dip" > 

     <RelativeLayout 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" > 

      <TextView 
       android:id="@+id/textView2" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="12dp" 
       android:gravity="center_horizontal" 
       android:text="@string/app_name" 
       android:textColor="#fff" 
       android:textSize="16sp" /> 

     </RelativeLayout> 
    </TableRow> 

문제는 그 결과를 (아래 이미지 참조)을 중심으로되지이다 제발?

답변

2

매우 쉽게 해결할 수 있습니다.

<RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" > 

그 방법은 상단에있는 TableRow의 전체 크기를 늘릴 것입니다 : 당신은 올바른 크기를 가지고 당신의 RelativeLayout을 변경해야합니다. 그런 다음 당신은 당신의 TextView이를 추가 할 수 있습니다

android:layout_centerInParent="true" 

TableRow에 걸쳐있는 RelativeLayout에서 TextView을, 중앙에.