Ahmed Mujtaba
Ahmed Mujtaba

Reputation: 2248

CoordinatorLayout not working properly with 2 child layouts

I have a CoordinatorLayout at root which has AppBarLayout that contains a LinearLayout that has 2 LinearLayouts as child. Let's call these child layouts A and B. I can't have contents of both A and B show at the same time. Contents of A show and B don't and when I delete contents of A only then contents of B show and vice versa. This is what is looks like when I have contents of both A and B inside the LinearLayout container.

enter image description here

A and B both have Textviews but only TextView of A shows and B doesn't.

Here's the code for the layout:

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">
    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true"
        android:theme="@style/Theme.AppCompat.Light.NoActionBar">
        <LinearLayout
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#ffff"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light">
            <LinearLayout
                android:orientation="vertical"
                android:minWidth="25px"
                android:minHeight="25px"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/A"
                android:padding="10dp">
                <TextView
                    android:text="Large Text"
                    android:textAppearance="?android:attr/textAppearanceLarge"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:id="@+id/title"
                    android:textColor="#000000"
                    android:fontFamily="sans-serif-light" />
            </LinearLayout>
            <LinearLayout
                android:orientation="horizontal"
                android:minWidth="25px"
                android:minHeight="25px"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/B"
                android:background="@drawable/border"
                android:padding="10dp">
                <TextView
                    android:text="Large Text"
                    android:textAppearance="?android:attr/textAppearanceLarge"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:id="@+id/textview"
                    android:textColor="#000000"
                    android:fontFamily="sans-serif-light" />
            </LinearLayout>
        </LinearLayout>
    </android.support.design.widget.AppBarLayout>
    <android.support.v7.widget.RecyclerView
        android:id="@+id/rv"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>

I have tried everything but I can't figure out what is wrong. The scroll behavior works fine but I can't see the contents of both A and B. Can anyone help?

Upvotes: 0

Views: 1296

Answers (1)

Ahmed Mujtaba
Ahmed Mujtaba

Reputation: 2248

I solved this by using FrameLayout instead of Linearlayout as a container for A and B.

Upvotes: 1

Related Questions