0

Can I set the blue view in the center of the black layout Knowing that the black layout is it's parent of parent

like in the image

center parent of parent

enter image description here

Ahmad Aghazadeh
  • 16,571
  • 12
  • 101
  • 98

1 Answers1

0

You have to change things around a bit, you can't put a view relative to a parent's parent.

You need a RelativeLayout as the root layout, and then you place the blue line centered vertically. Then you would place the red LinearLayouts above and below the blue layout. Something like this:

<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>
Francesc
  • 25,014
  • 10
  • 66
  • 84