状态栏下方的导航抽屉

3

如下图所示,导航抽屉中有四个项目。第一个项目被隐藏在状态栏下方。我希望它出现在工具栏下方(汉堡图标下方)。如果我尝试在代码中移动任何内容,那么我的可折叠工具栏就会出错,或者所有内容都会固定在顶部。 请问有什么解决方法吗? 以下是我的XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <android.support.v4.widget.DrawerLayout
        android:id="@+id/drawer_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

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

            <android.support.design.widget.AppBarLayout
                android:id="@+id/app_bar_layout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
                android:fitsSystemWindows="true">

                <android.support.design.widget.CollapsingToolbarLayout
                    android:id="@+id/collapsing_toolbar"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    app:layout_scrollFlags="scroll|exitUntilCollapsed"
                    app:contentScrim="?attr/colorPrimary"
                    app:expandedTitleMarginStart="48dp"
                    app:expandedTitleMarginEnd="64dp"
                    android:fitsSystemWindows="true">

                    <ImageView
                        android:src="@drawable/nerdz_main_page"
                        android:id="@+id/image"
                        android:layout_width="match_parent"
                        android:layout_height="400dp"
                        android:scaleType="fitXY"
                        android:fitsSystemWindows="true"
                        app:layout_collapseMode="parallax"/>

                    <android.support.v7.widget.Toolbar
                        android:id="@+id/toolbar"
                        android:layout_width="match_parent"
                        android:layout_height="?attr/actionBarSize"
                        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                        app:layout_collapseMode="pin" />

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

            <android.support.v4.widget.NestedScrollView
                android:id="@+id/scroll"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:clipToPadding="false"
                app:layout_behavior="@string/appbar_scrolling_view_behavior">

                <FrameLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">

                    <android.support.v7.widget.CardView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="24dp"
                        app:cardElevation="5dp"
                        android:text="this is a sample card "
                        app:cardUseCompatPadding="true">

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

                            <TextView
                                android:id="@+id/title"
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:textAppearance="@style/TextAppearance.AppCompat.Headline"/>

                            <TextView
                                android:id="@+id/description"
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:text="@string/lorem_ipsum"
                                android:textAppearance="@style/TextAppearance.AppCompat.Body1"/>
                        </LinearLayout>
                    </android.support.v7.widget.CardView>
                </FrameLayout>
            </android.support.v4.widget.NestedScrollView>
        </android.support.design.widget.CoordinatorLayout>

        <fragment
            android:id="@+id/fragment_navigation_drawer"
            android:name="com.example.abc.apptest.drawer"
            android:layout_width="300dp"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            app:layout="@layout/fragment_drawer"
            tools:layout="@layout/fragment_drawer" />
    </android.support.v4.widget.DrawerLayout>
</LinearLayout>

here is the screenshot of the navigation drawer

1个回答

6

将以下代码添加到您的布局xml中:

android:fitsSystemWindows="true"

就是这样。


在哪里添加它? - Faraz Ahmed
导航抽屉布局。 - Hardik Chauhan
是的,项目1现在可见了,但我想让导航抽屉在汉堡图标下面。有什么想法吗? - Faraz Ahmed
http://www.androidpolice.com/wp-content/uploads/2014/12/nexus2cee_Screenshot_2014-12-16-18-06-45.jpg当抽屉被滑动时,三条线会变成箭头。 - Faraz Ahmed

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接