小编Tha*_*ter的帖子

切换可见性AppBarLayout视图会导致加载的碎片出现间距问题


我遇到了新的Android Design Support Librar(http://android-developers.blogspot.com.ar/2015/05/android-design-support-library.html)的一个奇怪问题.如果我在AppBarLayout中放置其他内容(如LinearLayout)以及ToolBar并切换该内容的可见性,那么切换片段将在片段内容的顶部显示死区.

当切换内容的可见性时,AppBarLayout似乎没有正确调整父级CoordinatorLayout的大小.我的CoordinatorLayout包含在DrawerLayout中.我想根据显示的片段切换AppBarLayout中额外LinearLayout的可见性.

这是MainActivity的main.xml文件:

<android.support.v4.widget.DrawerLayout
        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/drawer_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true">

<android.support.design.widget.CoordinatorLayout
            android:layout_height="match_parent"
            android:layout_width="match_parent">

        <android.support.design.widget.AppBarLayout
                android:id="@+id/appBarLayout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

            <android.support.v7.widget.Toolbar
                    android:id="@+id/toolbar"
                    android:layout_width="match_parent"
                    android:layout_height="?attr/actionBarSize"/>

            <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical"
                    android:gravity="center_vertical"">

                <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:gravity="start"
                        android:text="Hello"/>
            </LinearLayout>

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

        <FrameLayout
           app:layout_behavior="@string/appbar_scrolling_view_behavior"
                android:id="@+id/content_frame"
                android:layout_width="match_parent"
                android:layout_height="match_parent"/>

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

  <android.support.design.widget.NavigationView
            android:id="@+id/navigation"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            app:menu="@menu/drawer"/>

</android.support.v4.widget.DrawerLayout>
Run Code Online (Sandbox Code Playgroud)

android material-design android-coordinatorlayout android-support-design android-appbarlayout

6
推荐指数
1
解决办法
887
查看次数