JOH*_*GAN 0 xml android navigation-drawer
有没有办法给Android导航视图自定义宽度,我正在使用Android工作室.我通过谷歌搜索尝试了不同的方式,但没有运气,请帮助我.
在处理不同屏幕尺寸时,最佳做法是提供自定义宽度吗?
这是我的xml代码
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/top_parent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".Dashbored">
<include
android:id="@+id/tool_bar"
layout="@layout/tool_bar">
</include>
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/tool_bar"
android:elevation="7dp"
android:fitsSystemWindows="true"
tools:openDrawer="end">
<LinearLayout
android:id="@+id/linear_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<FrameLayout
android:id="@+id/frame_container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include layout="@layout/f_home_screen" />
</FrameLayout>
</LinearLayout>
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="end"
android:background="#0284fe"
android:fitsSystemWindows="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include
android:id="@+id/navheader"
layout="@layout/nav_header" />
<ListView
android:id="@+id/lst_menu_items"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:divider="@null"
android:dividerHeight="0dp"
/>
</LinearLayout>
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
Run Code Online (Sandbox Code Playgroud)
谢谢
Fer*_*med 10
您可以NavigationView使用属性更改宽度android:layout_width="CUSTOM_WIDTH"
如果你想显示相同的width所有设备,那么你可以使用android:maxWidth="CUSTOM_WIDTH"与android:layout_width="wrap_content"
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:maxWidth="200dp"
android:layout_gravity="end"
android:background="#0284fe"
android:fitsSystemWindows="true">
Run Code Online (Sandbox Code Playgroud)
仅供参考,最好定义分辨率特定文件的width值.200dpdimens.xml
希望这会有所帮助〜