Faced such a problem. On the main screen layout LinearLayout are two layout 'a - RelativeLayout with the menu and LinearLayout with fragments. RelativeLayout takes 50dp. LinearLayout takes up the rest of the screen.

While the menu was at the top, everything was ok. But as soon as I swapped them, LinearLayout took up the whole screen ( match_parent ) and RelativeLayout disappeared below.

 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/main_linear_container" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/colorBackground" android:orientation="vertical"> <LinearLayout android:id="@+id/timer_main_frame" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <FrameLayout android:id="@+id/main_fragment_view" android:layout_width="match_parent" android:layout_height="250dp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent"> </FrameLayout> <FrameLayout android:id="@+id/fragment_below_main" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin="8dp" android:layout_marginEnd="8dp" android:layout_marginLeft="8dp" android:layout_marginRight="8dp" android:layout_marginStart="8dp" android:layout_marginTop="8dp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="1.0" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" app:layout_constraintVertical_bias="1.0" app:srcCompat="@drawable/clock_rewersed"> </FrameLayout> </LinearLayout> <RelativeLayout android:layout_width="match_parent" android:layout_height="50dp"> <ImageView android:id="@+id/timer" android:layout_width="50dp" android:layout_height="50dp" android:layout_alignTop="@+id/fill_day_rate" android:layout_marginLeft="10dp" android:layout_marginRight="10dp" android:layout_toStartOf="@+id/fill_day_rate" android:onClick="onClickMenu" android:padding="10dp" app:srcCompat="@drawable/timer" /> </RelativeLayout> </LinearLayout> 

I need LinearLayout occupy the rest of the RelativeLayout area, so I can’t set a height limit for it. Numerous experiments with markings and weight lead to nothing.

    1 answer 1

    For LinearLayout , which is with id timer_main_frame , set the height to 0dp and the android:layout_weight="1" property android:layout_weight="1" . It should work.

    • Thank! Earned! - Vyacheslav Chernyshov