[英]layout_gravity= "start" is not working in Navigation View
layout_gravity attribute is not showing in Navigation View.I want to give the layout_gravity = "start" but it is not showing. layout_gravity 属性没有显示在导航视图中。我想给 layout_gravity = "start" 但它没有显示。
Here is my layout.xml file这是我的 layout.xml 文件
<androidx.drawerlayout.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:context=".HomeActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.appcompat.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
android:elevation="@dimen/_4sdp"
android:background="@color/colorPrimary">
</androidx.appcompat.widget.Toolbar>
</LinearLayout>
<com.google.android.material.navigation.NavigationView
android:layout_width="match_parent"
android:layout_height="match_parent"/>
If you want to see your Navigation View you must add tools:openDrawer:"start"
in the DrawerLayout
.如果你想看到你的导航视图必须添加
tools:openDrawer:"start"
在DrawerLayout
。 This will set your Drawer as visible only in the layout editor, in the app it will be hidden until the user opens it.这会将您的 Drawer 设置为仅在布局编辑器中可见,在应用程序中它将被隐藏,直到用户打开它。
Remember also to set the Gravity, the Menu and the Header Layout (if you have one) with还要记住设置重力,菜单和标题布局(如果你有的话)
android:layout_gravity="start"
app:menu="@menu/your_menu"
app:headerLayout="@layout/your_header_layout"
in your NavigationView.在您的导航视图中。
Hope it helps!希望能帮助到你!
add this into drawer tools:openDrawer="start"
and add this into navigation将此添加到抽屉
tools:openDrawer="start"
并将其添加到导航中
android:layout_gravity="start"
and don't forget to add the menu app:menu="@menu/menu"
并且不要忘记添加菜单
app:menu="@menu/menu"
Just copy and past the below code and adjust it and it will work只需复制并粘贴以下代码并进行调整即可
<com.google.android.material.navigation.NavigationView
android:id="@+id/navigation"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start|left"
app:headerLayout="@layout/header"
app:menu="@menu/navigation_menu" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.