AppBarLayout - Layout sometimes invisible once it

2019-03-01 01:49发布

问题:

I have a problem where sometimes the AppBarLayout will not show its full content all the time when you play around with it:

<android.support.design.widget.CoordinatorLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent">


    <android.support.v7.widget.RecyclerView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"/>


    <android.support.design.widget.AppBarLayout
            android:orientation="vertical"
            android:layout_height="148dp"
            android:layout_width="match_parent">

        <android.support.design.widget.TabLayout
                app:layout_scrollFlags="scroll|enterAlways"
                android:layout_height="48dp"
                android:background="@color/primarycolor"
                .../>

        <RelativeLayout
                app:layout_scrollFlags="scroll|enterAlways"
                android:background="@color/white"
                android:layout_height="100dp"
                ...>
        </RelativeLayout>

    </android.support.design.widget.AppBarLayout>

</android.support.design.widget.CoordinatorLayout>

A solution provided is

CoordinatorLayout Toolbar invisible on enter until full height

BUT: it provides a full line that is not the same color as the primary color I specify in the bottom layout, because its background is white. Thoughts?

回答1:

This is a solution extending the one provided above: Use this instead of the one provided, which will blend the appbarlayout and the subtle shadow elevation below it.

<View
    android:id="@+id/appbar_bottom"
    android:layout_width="match_parent"
    android:layout_height=".3dp"
    android:background="#606060"
    android:visibility="visible"/>

and the resultant layout:

<android.support.design.widget.AppBarLayout
        android:orientation="vertical"
        android:layout_height="148.3dp"
        android:layout_width="match_parent">

    <android.support.design.widget.TabLayout
            app:layout_scrollFlags="scroll|enterAlways"
            android:layout_height="48dp"
            android:background="@color/primarycolor"
            .../>

    <RelativeLayout
            app:layout_scrollFlags="scroll|enterAlways"
            android:background="@color/white"
            android:layout_height="100dp"
            ...>
    </RelativeLayout>

    <View
        android:id="@+id/appbar_bottom"
        android:layout_width="match_parent"
        android:layout_height=".3dp"
        android:background="#606060"
        android:visibility="visible"/>
</android.support.design.widget.AppBarLayout>