【问题标题】:Navigation drawer alignment issue导航抽屉对齐问题
【发布时间】:2016-03-14 09:00:16
【问题描述】:

我在操作栏下制作了导航抽屉。它在 Jellybean os 上运行良好,但在 marshmallow os 上却不工作..

在软糖中 我的活动主要 xml 是

<?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_checkout"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <FrameLayout
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
    <!-- The navigation drawer -->
    <ExpandableListView
        android:id="@+id/left_drawer"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="#fdfdfd"
        android:choiceMode="singleChoice"
        android:divider="@android:color/transparent"
        android:dividerHeight="0dp"
        android:groupIndicator="@null"
        android:layout_marginTop="?attr/actionBarSize"
        />

</android.support.v4.widget.DrawerLayout>

【问题讨论】:

    标签: android navigation-drawer android-6.0-marshmallow android-4.3-jelly-bean


    【解决方案1】:

    一个抽屉布局只允许有 2 个孩子,第一个是主要内容视图,第二个是抽屉。您需要将前两个视图组合成一个线性布局。

    <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">
    
        <include
        layout="@layout/app_bar_checkout"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
    
        <FrameLayout
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
    
    </LinearLayout>
    

    【讨论】:

    • 您是否实施了建议的更改?
    • 是的。当我实现这个时。输出没有变化。在棉花糖中,导航抽屉不在操作栏下..谢谢
    • 所以你想要它在操作栏下?建议的解决方案将其放在操作栏的顶部。要将其放在操作栏下方,您需要定义一个线性布局,其第一个孩子将是操作栏,第二个孩子将是抽屉布局。你需要从 Drawerlayout 中删除 app_bar_checkout 元素
    【解决方案2】:

    我是这样弄的

    <LinearLayout 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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:fitsSystemWindows="true"
    tools:context="com.qproinnovations.schoolmanagement.activity.HomeActivity">
        <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.v7.widget.Toolbar>
    
        </android.support.design.widget.AppBarLayout>
    
        <android.support.v4.widget.DrawerLayout
            android:id="@+id/drawer_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            tools:openDrawer="start">
    
            <include layout="@layout/content_home" />
    
            <android.support.design.widget.NavigationView
                android:id="@+id/nav_view"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_gravity="start"
                android:fitsSystemWindows="true"
                app:menu="@menu/activity_home_drawer" />
    
    
        </android.support.v4.widget.DrawerLayout>
    
    
    
    </LinearLayout>
    

    【讨论】:

      猜你喜欢
      • 2019-01-09
      • 2018-11-12
      • 2013-06-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-22
      相关资源
      最近更新 更多