【问题标题】:Android - aligning view in RelativeLayout to a View in TableLayoutAndroid - 将 RelativeLayout 中的视图与 TableLayout 中的视图对齐
【发布时间】:2012-08-03 17:29:51
【问题描述】:

我的根布局是RelativeLayout,其中包含一些TextView、Button 和ImageView。在屏幕的底部,我有一个TableLayout,它代表一个 4x4 的 TextView 网格。我想显示一个视图(例如 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 中的另一个视图对齐,但我希望得到确认,或者更好地提供有关如何解决此问题的建议。

【问题讨论】:

    标签: android android-layout


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-11
      • 2013-08-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多