简体   繁体   English

layout_gravity="start" 在导航视图中不起作用

[英]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.

相关问题 android:layout_gravity =“ end”在真实设备中编译时不起作用 - android:layout_gravity=“end” not working when compiling in a real device 如何在 Java 而不是 XML 中以编程方式设置视图的重力和 layout_gravity? - How can I set a view's gravity and layout_gravity programmatically in Java instead of XML? Android - 以编程方式为LinearLayout设置Layout_Gravity - Android - Set Layout_Gravity programmatically for LinearLayout android的Java方法:layout_gravity - Java method for android:layout_gravity 以编程方式为FrameLayout的Child设置layout_gravity? - Programmatically set layout_gravity for a FrameLayout's Child? android:layout_gravity无法按预期工作 - android:layout_gravity doesn't work as expected Image / ViewPager将无法正确使用android:layout_gravity =“ bottom”和android:layout_alignParentBottom =“ true” - Image/ViewPager will not correctly use android:layout_gravity=“bottom” and android:layout_alignParentBottom=“true” 为什么将layout_gravity设置为left / right在水平LinearLayout中不起作用? - Why does layout_gravity set to left/right have no effect in horizontal LinearLayout? 如何在android上的Xml上设置视图布局重力? - How to set the View layout gravity on Xml on android? 在将布局膨胀对象添加到视图时设置其重力 - Setting gravity of a layout inflated object while adding it to a view
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM