有没有办法给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>
由于
答案 0 :(得分:8)
您可以使用属性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">
FYI ,最好将width
值200dp
定义为解决特定dimens.xml
文件。
希望这会有所帮助〜
答案 1 :(得分:1)
试
android:maxWidth="250dp" // you should define width in dimens.xml file instead of hardcode it