2010-09-26 29 views
1

我知道有很多關於這個問題的問題已經浮出水面,但我已經閱讀了一堆,但仍然無法讓我的第三欄對齊到右側。Android:無法將TableLayout的重力設置爲正確

<?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" 
    android:background="#FFFFFF" 
    android:stretchColumns="2" 
> 
    <TableRow> 

<ImageView 
    android:src="@drawable/blue_light" 
    android:layout_height="48px" 
    android:layout_width="48px" 
    android:padding="3dp" 
    android:layout_margin="3dp" 
    android:layout_column="1"/> 

    <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginLeft="10px" 
    android:layout_gravity="center_vertical" 
    android:layout_column="2"> 

    <TableRow> 
    <TextView 
    android:id="@+id/row_title" 
    android:textColor="#000000" 
    android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textStyle="bold" /> 
    </TableRow> 

    <TableRow> 
    <TextView 
    android:id="@+id/row_author" 
    android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textColor="#9E9E9E" 
     android:textStyle="italic|bold"/> 
    </TableRow> 

    </TableLayout> 

    <TableLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_column="3" 
    android:layout_gravity="center_vertical|right" 
    android:gravity="center_vertical|right" 
    > 

    <TableRow> 
    <TextView 
    android:textColor="#1F9C29" 
    android:textSize="15dp" 
    android:id="@+id/row_txt1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textStyle="bold" /> 
    </TableRow> 

    <View 
    android:layout_height="1dp" 
    android:background="#000000" 
    android:layout_marginRight="3dp" 
    /> 

    <TableRow> 
    <TextView 
    android:textColor="#1B27D1" 
    android:id="@+id/row_txt2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textStyle="bold"/> 
    </TableRow> 

    </TableLayout> 
    </TableRow> 
</TableLayout> 

我在做什麼錯了?

回答

5

無法讓我的第三列對齊到右側。

關閉袖口,我懷疑嵌套TableLayout小工具不會工作得非常好。雖然TableLayout被設計爲模仿HTML表格「API」,但是類比是有限制的。

如果您希望「第三列對齊到右邊」,則將所有內容放入外部TableLayout,然後在該列中的所有窗口小部件上嘗試android:layout_gravity="right"

+0

是的,就是這樣。我轉而在TableLayout中使用嵌套的LinearLayouts來簡化XML。謝謝! – 2010-09-26 16:08:06

0

我有同樣的問題,並用以下解決它:

裏面的TableRow屬性添加兩個以下行:

android:layout_gravity="center" 
android:gravity="right" 

如果使用Layout_gravity =正確的,由於某種原因,根本不起作用。 享受, 阿德里安。