2013-12-12 20 views
1

有兩個TableRows在TableLayout,並且每個的TableRow包含兩個TextViews:TextView的對準

<?xml version="1.0" encoding="utf-8"?> 
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" > 

    <TableRow 
     android:id="@+id/tableRow1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="10dp" 
     android:layout_marginRight="10dp" > 

     <TextView 
      android:id="@+id/textTime" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" /> 

     <TextView 
      android:id="@+id/textTitle" 
      android:layout_width="fill_parent" 
      android:layout_height="match_parent" 
      android:layout_marginLeft="10dp" /> 

    </TableRow> 

     <TableRow 
      android:id="@+id/tableRow2" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="63dp" 
      android:layout_marginRight="10dp" > 

      <TextView 
       android:id="@+id/textHall" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" /> 

      <TextView 
       android:id="@+id/textPrice" 
       android:layout_width="fill_parent" 
       android:layout_height="match_parent" 
       android:layout_marginLeft="10dp" /> 

    </TableRow> 

</TableLayout> 

如果textHall包含一個短WordtextTitleSome Text)位於正確的位置:

scr1

但如果textHall包含一個長Second WordtextTitle之前(Some Text)出現一個大缺口:

scr2

的原因是什麼?

謝謝。

回答

3

你應該給你的佈局和行權重。我修改了你的代碼。這是應該的。

<TableRow 
    android:id="@+id/tableRow1" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_marginLeft="10dp" 
    android:layout_marginRight="10dp" 
    android:layout_weight="1" 
    android:weightSum="2" > 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_weight="2" 
     android:orientation="horizontal" > 

     <TextView 
      android:id="@+id/textTime" 
      android:layout_width="wrap_content" 
      android:layout_height="fill_parent" 
      android:text="10:30" /> 

     <TextView 
      android:id="@+id/textTitle" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:layout_gravity="left" 
      android:layout_marginLeft="10dp" 
      android:text="Some Text" /> 
    </LinearLayout> 
</TableRow> 

<TableRow 
    android:id="@+id/tableRow2" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginLeft="63dp" 
    android:layout_marginRight="10dp" 
    android:layout_weight="1" 
    android:weightSum="2" > 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_weight="2" 
     android:orientation="horizontal" > 

     <TextView 
      android:id="@+id/textHall" 
      android:layout_width="wrap_content" 
      android:layout_height="fill_parent" 
      android:text="Some Word" /> 

     <TextView 
      android:id="@+id/textPrice" 
      android:layout_width="0dp" 
      android:layout_height="fill_parent" 
      android:layout_marginLeft="10dp" 
      android:layout_weight="1" 
      android:text="200" /> 
    </LinearLayout> 
</TableRow> 

如你願意,你可以把任何保證金價值爲你的第二排。

希望這可能有所幫助。

1

textHalltextTime雙雙掉進同一列,並且列的寬度設置爲textHall的寬度(因爲這是有更多的寬度),因此,當你在textHall增加文本您textTime的TextView的寬度增加。