每个人,我是Android开发的新手,我正在尝试使用自定义导航抽屉创建一个应用程序。我有一个代码:
Range("L3").Select
ActiveCell.FormulaR1C1 = "=+IF(R3C5=R[-2]C,R3C1,"" "")"
Selection.AutoFill Destination:=Range("L3:W3"), Type:=xlFillDefault
Range("L4").Select
ActiveCell.FormulaR1C1 = "=+IF(R4C5=R[-3]C,R4C1,"" "")"
Selection.AutoFill Destination:=Range("L4:W4"), Type:=xlFillDefault
Range("L5").Select
ActiveCell.FormulaR1C1 = "=+IF(R5C5=R[-4]C,R5C1,"" "")"
Selection.AutoFill Destination:=Range("L5:W5"), Type:=xlFillDefault
Next
这段代码可以很好地创建导航抽屉。虽然,当我提供这样的布局时,我的导航抽屉似乎在整个屏幕上发生,并且不会对任何动作做出反应:
<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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="@layout/fragment_home" />
</LinearLayout>
<ListView
android:id="@+id/navigation_list_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start"/>
</android.support.v4.widget.DrawerLayout>
我的JAVA代码是:
<?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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="@layout/fragment_home" />
</LinearLayout>
<android.support.design.widget.NavigationView
android:id="@+id/navigation_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/navigation_menu_background" >
<include layout="@layout/navigation_menu_header" />
<ListView
android:id="@+id/navigation_list_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start"/>
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
哪里可能是导致此问题的问题?为什么会这样呢?
答案 0 :(得分:0)
它占据整个屏幕的原因是因为你将“match_parent”指定为高度和宽度值 - 它与整个视图的大小相匹配,因此也与整个屏幕相匹配。
答案 1 :(得分:0)
android:layout_gravity="start"
属性需要位于您用于抽屉的View
上;在这种情况下,NavigationView
。
您可能还想将layout_width
设置为"wrap_content"
,因此抽屉不会涵盖比应有的更多内容。 NavigationView
会将自己衡量到适当的宽度,但如果您要使用另一个View
,则可能需要使用精确的度量而非包装;例如,"240dp"
。