2012-08-03 71 views
2

我的根佈局是RelativeLayout,它包含一些TextView,Button和ImageViews。在屏幕的底部,我有一個TableLayout,它代表了一個4x4的TextViews網格。我想在網格中顯示與每個TextView的右下角對齊的視圖(例如TextView)Android - 將RelativeLayout中的視圖對齊到TableLayout中的視圖

所以我有一個

<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中的Views只能與同一個RelativeLayout中的另一個視圖對齊,但我希望這個確認或更好的建議來解決這個問題。

回答

1

正確,relativelayout只能對齊其子節點。你需要每一個細胞在你的表中包含一個相對佈局,僞代碼:

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

你也可以用垂直的LinearLayout和重力這樣做是爲了右對齊新的視圖。

相關問題