3 回答

TA貢獻(xiàn)1812條經(jīng)驗 獲得超5個贊
您可以在您的 RelativeLayout 內(nèi)嵌套另一個布局,例如 LinearLayout 或另一個 RelativeLayout,然后將兩個兄弟視圖放在其中。或者,您可以使用 android:layout_above 在 RelativeLayout 內(nèi)將兩者鏈接在一起。

TA貢獻(xiàn)1817條經(jīng)驗 獲得超14個贊
您可以在使用RelativeLayout
.
例如:
<RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:id="@+id/tv1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true"/> <TextView android:id="@+id/tv2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_below="@id/tv1"/></RelativeLayout>
此示例布局將顯示兩個TextView
,均與其父項相關(guān)居中,并將一個放置在另一個下方。
有許多參數(shù)可用于將視圖放置在此布局上,如下面的示例來自文檔:
可用于 RelativeLayout 中的視圖的許多布局屬性中的一些包括:
android:layout_alignParentTop
如果為“true”,則使此視圖的頂部邊緣與父視圖的頂部邊緣匹配。
android:layout_centerVertical
如果為“true”,則此子項在其父項內(nèi)垂直居中。
android:layout_below
將此視圖的上邊緣定位在使用資源 ID 指定的視圖下方。
android:layout_toRightOf
將此視圖的左邊緣定位到使用資源 ID 指定的視圖的右側(cè)。
您可以在此處閱讀有關(guān)這些參數(shù)的更多信息。
我建議您閱讀有關(guān)RelativeLayout
檢查其工作原理的文檔。
現(xiàn)在,最好看看另一個名為 的布局管理器ConstraintLayout
,它有點像RelativeLayout
,但功能更強大。看看這里,看看它是如何工作的。
此外,該站點還展示了如何使用 模仿其他布局行為ConstraintLayout
,請查看!
添加回答
舉報