首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >NavigationDrawer占据了整个屏幕

NavigationDrawer占据了整个屏幕
EN

Stack Overflow用户
提问于 2018-12-13 19:49:25
回答 1查看 106关注 0票数 0

我正在尝试实现从屏幕右侧打开的简单NavigationDrawer。当我运行应用程序时,抽屉会占据整个屏幕,而不是我指定的320dp?这里我漏掉了什么?

代码语言:javascript
运行
复制
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<android.support.v4.widget.DrawerLayout
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <FrameLayout
        android:id="@+id/main_content"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <include
            android:id="@+id/app_bar"
            layout="@layout/common_app_bar" />

        <com.veriori.veriori.view.VerioriLayout
            android:id="@+id/layer_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent">


        </com.veriori.veriori.view.VerioriLayout>

    </FrameLayout>

    <RelativeLayout
        android:layout_width="320dp"
        android:layout_height="match_parent"
        android:background="@color/white"
        android:gravity="end">

        <ImageView
            android:layout_width="14dp"
            android:layout_height="14dp"
            android:layout_alignParentEnd="true"
            android:layout_margin="21dp"
            android:background="@drawable/ic_cross" />

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:layout_marginLeft="26dp"
            android:orientation="vertical">

            <LinearLayout
                android:id="@+id/drawer_item_start"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content">

                <ImageView
                    android:layout_width="20dp"
                    android:layout_height="20dp"
                    android:layout_gravity="center_vertical"
                    android:background="@drawable/ic_drawer_start" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="14dp"
                    android:text="@string/drawer_start"
                    android:theme="@style/TextAppearance_5" />

            </LinearLayout>

            <LinearLayout
                android:id="@+id/drawer_item_history"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="21dp">

                <ImageView
                    android:layout_width="20dp"
                    android:layout_height="20dp"
                    android:layout_gravity="center_vertical"
                    android:background="@drawable/ic_drawer_history" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="14dp"
                    android:text="@string/drawer_history"
                    android:theme="@style/TextAppearance_5" />

            </LinearLayout>

            <LinearLayout
                android:id="@+id/drawer_item_report"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="21dp">

                <ImageView
                    android:layout_width="20dp"
                    android:layout_height="20dp"
                    android:layout_gravity="center_vertical"
                    android:background="@drawable/ic_drawer_report" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="14dp"
                    android:text="@string/drawer_report"
                    android:theme="@style/TextAppearance_5" />

            </LinearLayout>

            <LinearLayout
                android:id="@+id/drawer_item_settings"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="21dp">

                <ImageView
                    android:layout_width="20dp"
                    android:layout_height="20dp"
                    android:layout_gravity="center_vertical"
                    android:background="@drawable/ic_drawer_settings" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="14dp"
                    android:text="@string/drawer_settings"
                    android:theme="@style/TextAppearance_5" />

            </LinearLayout>

            <TextView
                android:id="@+id/drawer_manufacturers"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="36dp"
                android:layout_marginTop="21dp"
                android:text="@string/drawer_manufacturers"
                android:textColor="@color/colorSecondaryText"
                android:theme="@style/TextAppearance_3" />

            <TextView
                android:id="@+id/drawer_about"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="36dp"
                android:layout_marginTop="14dp"
                android:text="@string/drawer_veriori"
                android:textColor="@color/colorSecondaryText"
                android:theme="@style/TextAppearance_3" />

            <TextView
                android:id="@+id/drawer_agreements"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="36dp"
                android:layout_marginTop="14dp"
                android:text="@string/drawer_agreements"
                android:textColor="@color/colorSecondaryText"
                android:theme="@style/TextAppearance_3" />

        </LinearLayout>
    </RelativeLayout>
</android.support.v4.widget.DrawerLayout>

EN

回答 1

Stack Overflow用户

发布于 2018-12-13 20:36:12

而不是

代码语言:javascript
运行
复制
<android.support.v4.widget.DrawerLayout
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

替换为:

代码语言:javascript
运行
复制
<android.support.v4.widget.DrawerLayout
    android:id="@+id/drawer_layout"
    android:layout_width="320dp"
    android:layout_height="match_parent">

并从您的RelativeLayout中删除320dp值。

希望这能帮到你。

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53761214

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档