我正在尝试实现从屏幕右侧打开的简单NavigationDrawer。当我运行应用程序时,抽屉会占据整个屏幕,而不是我指定的320dp?这里我漏掉了什么?
<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>
发布于 2018-12-13 20:36:12
而不是
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">替换为:
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
android:layout_width="320dp"
android:layout_height="match_parent">并从您的RelativeLayout中删除320dp值。
希望这能帮到你。
https://stackoverflow.com/questions/53761214
复制相似问题