AppBarLayout - Layout sometimes invisible once it enters view (even if it's not entered)

百般思念 提交于 2019-12-31 03:52:10

问题


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>


来源:https://stackoverflow.com/questions/31084658/appbarlayout-layout-sometimes-invisible-once-it-enters-view-even-if-its-not

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!