我有以下导航抽屉的代码,我正在使用该属性 机器人:layout_marginLeft =" 620dp"指定抽屉布局打开时抽屉占用的空间(宽度)。 而不是硬编码固定宽度620dp我想指定相似的重量或是否有任何类似的方法,如重量这个属性?
<android.support.design.widget.NavigationView
android:id="@+id/navigation"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="@layout/header"
android:layout_marginLeft="620dp"
android:fitsSystemWindows="true"
app:itemBackground="@android:color/transparent"
>
<ExpandableListView
android:id="@+id/navigationmenu"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="130dp"
android:divider="@android:color/transparent"
android:listSelector="@android:color/transparent"
android:dividerHeight="0dp"
android:fitsSystemWindows="true"
android:background="@android:color/white">
</ExpandableListView>
</android.support.design.widget.NavigationView>
答案 0 :(得分:1)
在布局的相应活动/片段中,您可以通过ID找到NavigationView:
dummyNavigationView = (NavigationView) findViewById(R.id.navigation);
然后您可以访问和更改与其关联的所有属性,包括layout_width和height;)
答案 1 :(得分:0)
Apply similar to this:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout 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:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include
layout="@layout/app_bar_main2"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ExpandableListView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_main2"
app:menu="@menu/activity_main2_drawer" />
</android.support.v4.widget.DrawerLayout>