2

我的根布局是一个RelativeLayout,其中包含一些 TextViews、Buttons 和 ImageViews。在屏幕的底部,我有一个TableLayout代表 4x4 网格的 TextViews。我想显示一个与网格中每个 TextView 的右下角对齐的视图(例如 TextView)。

所以我有一个

 <TableLayout ...>
   <TableRow ...>
     <TextView android:id="@+id/x0y0".../>
     <TextView android:id="@+id/x0y1".../>
   ....
 </TableLayout>
 ...
 <TextView  android:layout_alignTop="@id/x0y0"
    android:layout_alignLeft="@id/x0y0" ... />
 <TextView  android:layout_alignTop="@id/x1y1"
    android:layout_alignLeft="@id/x1y1" ... />

但它位于屏幕的左上角。我怀疑RelativeLayout 中的视图只能与同一个RelativeLayout 中的另一个视图对齐,但我希望得到确认,或者更好的是关于如何解决这个问题的建议。

4

1 回答 1

1

没错,relativelayout 只能对齐它的子节点。您需要表格中的每个单元格都包含一个相对布局,伪代码:

<TableRow ...>
 <RelativeLayout ...>
  <TextView id=id/x0y0 alignParentTop="true" alignParentLeft="true" ...>
  <View alignParentRight="true" layout_below=id/x0y0 ...>
 </RelativeLayout>

您也可以使用垂直 LinearLayout 和重力来右对齐新视图。

于 2012-08-03T17:35:45.477 回答