导航抽屉位于状态栏下方

时间:2015-10-10 16:01:09

标签: android android-layout

如下图所示,导航抽屉中有四个项目。第一个隐藏在状态栏下。我想在工具栏下方(汉堡图标下方)。如果我尝试移动代码中的任何内容,那么我的折叠工具栏就会混乱,或者所有内容都会固定在顶部。 有帮助吗? 这是我的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 个答案:

答案 0 :(得分:4)

将其添加到布局xml中,

android:fitsSystemWindows="true"

就是这样。