开发者社区> 问答> 正文

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

导航视图中未显示layout_gravity属性。我想给layout_gravity =“ start”,但未显示。

这是我的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"/>

问题来源:Stack Overflow

展开
收起
montos 2020-03-26 10:26:24 413 0
1 条回答
写回答
取消 提交回答
  • 如果你想看到你的导航视图必须添加tools:openDrawer:"start"的DrawerLayout。这会将您的抽屉设置为仅在布局编辑器中可见,在应用程序中它将被隐藏,直到用户打开它为止。

    还记得用以下方法设置重力,菜单和页眉布局(如果有的话)

    android:layout_gravity="start"
    app:menu="@menu/your_menu"
    app:headerLayout="@layout/your_header_layout"
    

    在您的NavigationView中。

    希望能帮助到你!

    回答来源:Stack Overflow

    2020-03-26 10:26:41
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载