Second layout is not showing with include tag in android studio

In your first layout, you have

android:layout_height="match_parent"

so it is taking up the entire height of your main layout. Change that to

android:layout_height="wrap_content"

and you should be good.

From the docs

The root View should be exactly how you'd like it to appear in each layout to which you add this layout.

Note that

You can also override all the layout parameters (any android:layout_* attributes) of the included layout's root view by specifying them in the <include/> tag.


I'm not yet sure if this will solve your problem, but can you try adding android:layout_width and android:layout_height in your included layout as well as layout weight?

<include layout="@layout/first_layout"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"/>

<include layout="@layout/second_layout"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"/>

Added info

The reason why you have that problem is because both your layouts uses match_parent for the height. That means that at the first layout, it will match the size of the parent (which in this case is the whole screen), thus, the first layout will occupy the whole screen and the second layout won't appear.

In this solution, you are telling both layouts to consume only half of the screen by using the layout_weight.


You should use RelativeLayout on your main layout. If you use LinearLayout one item will always be shown bellow the previous element and since both yours layout are match_parent the second won't be shown.