我可以在黑色布局的中心设置蓝色视图吗知道黑色布局是它的父级
像在图像中
您必须稍微改变一下,您不能相对于父母的父母放置一个视图。
您需要一个 RelativeLayout 作为根布局,然后将蓝线垂直居中放置。然后将红色的 LinearLayouts 放置在蓝色布局的上方和下方。像这样的东西:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<View
android:id="@+id/blue_layout"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_centerVertical="true"
android:background="#ff0000ff" />
<LinearLayout
android:id="@+id/above"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@id/blue_layout"
android:orientation="vertical">
</LinearLayout>
<LinearLayout
android:id="@+id/below"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/blue_layout"
android:orientation="vertical">
</LinearLayout>
</RelativeLayout>