删除api版本中出现的DrawerLayout顶部填充> 21

时间:2016-05-26 03:45:19

标签: android android-layout drawerlayout

所以,基本上我用自定义菜单实现了drawerLayout(我使用的是recyclerView而不是navigationView)。如果我在最新版本的android(> lollipop)中运行应用程序,则会出现顶部填充。无论如何要删除顶部填充?我试图在drawerLayout上设置fitSystemWindows=true但没有用。

代码

<android.support.v4.widget.DrawerLayout
        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"
        tools:openDrawer="start">

        <include
            layout="@layout/app_bar_store_landing"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

        <android.support.v4.widget.NestedScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            android:fitsSystemWindows="true">
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical">

                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="50dp"
                    android:background="@color/drawer_bg"
                    android:paddingLeft="20dp">
                    <ImageView
                        android:id="@+id/menuIcon"
                        android:layout_width="35dp"
                        android:layout_height="35dp"
                        android:layout_centerVertical="true"
                        android:src="@drawable/location_menu"
                        android:layout_marginRight="10dp"/>

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:orientation="vertical"
                        android:layout_centerVertical="true"
                        android:layout_toRightOf="@+id/menuIcon">
                        <TextView
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:text="Jalan Tunku Ismail"
                            android:textColor="@android:color/white"
                            android:ellipsize="end"
                            android:singleLine="true"
                            android:textStyle="bold"/>
                        <TextView
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:text="Tap to change location"
                            android:textColor="@color/grey_text" />
                    </LinearLayout>
                </RelativeLayout>


                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="50dp"
                    android:background="@color/drawer_bg"
                    android:paddingLeft="20dp">
                    <ImageView
                        android:id="@+id/menuIcon2"
                        android:layout_width="35dp"
                        android:layout_height="35dp"
                        android:layout_centerVertical="true"
                        android:src="@drawable/store_menu"
                        android:layout_marginRight="10dp"/>
                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:orientation="vertical"
                        android:layout_centerVertical="true"
                        android:layout_toRightOf="@+id/menuIcon2">
                        <TextView
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:text="Jaya Grocer, Kuala Lumpur"
                            android:textColor="@android:color/white"
                            android:ellipsize="end"
                            android:singleLine="true"
                            android:textStyle="bold"/>
                        <TextView
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:text="Tap to change store"
                            android:textColor="@color/grey_text" />
                    </LinearLayout>
                </RelativeLayout>

                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="50dp"
                    android:background="@color/drawer_bg"
                    android:paddingLeft="20dp">
                    <ImageView
                        android:id="@+id/menuIcon3"
                        android:layout_width="35dp"
                        android:layout_height="35dp"
                        android:src="@drawable/my_account"
                        android:layout_centerVertical="true"
                        android:layout_marginRight="10dp"/>
                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:orientation="vertical"
                        android:layout_centerVertical="true"
                        android:layout_toRightOf="@+id/menuIcon3">
                        <TextView
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:text="My Account"
                            android:textColor="@android:color/white"
                            android:ellipsize="end"
                            android:singleLine="true"
                            android:textStyle="bold"/>
                    </LinearLayout>
                </RelativeLayout>

                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="50dp"
                    android:background="@color/drawer_bg"
                    android:paddingLeft="20dp">
                    <ImageView
                        android:id="@+id/menuIcon4"
                        android:layout_width="35dp"
                        android:layout_height="35dp"
                        android:layout_centerVertical="true"
                        android:src="@drawable/my_shopping_list"
                        android:layout_marginRight="10dp"/>
                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:orientation="vertical"
                        android:layout_centerVertical="true"
                        android:layout_toRightOf="@+id/menuIcon4">
                        <TextView
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:text="My Shopping List"
                            android:textColor="@android:color/white"
                            android:ellipsize="end"
                            android:singleLine="true"
                            android:textStyle="bold"/>
                    </LinearLayout>
                </RelativeLayout>

                <View
                    android:layout_width="match_parent"
                    android:layout_height="1dp"
                    android:background="@color/grey_text" />

                <android.support.v7.widget.RecyclerView
                    android:id="@+id/menuList"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"/>
            </LinearLayout>
        </android.support.v4.widget.NestedScrollView>
    </android.support.v4.widget.DrawerLayout>

截图:

左 - Lolliop,右 - Kitkat enter image description here

固定!

在NestedScrollView中删除android:fitsSystemWindows="true"可以解决问题。

1 个答案:

答案 0 :(得分:1)

好的,发现了这个bug。罪魁祸首是NestedScrollView中的android:fitsSystemWindows="true"。删除此行,它解决了我的问题。我想知道为什么它不影响旧版本的android(&lt; Kitkat)。