首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法在工具栏下面执行导航抽屉操作

无法在工具栏下面执行导航抽屉操作
EN

Stack Overflow用户
提问于 2017-10-27 13:26:51
回答 1查看 293关注 0票数 2

如何配合工具栏下的导航抽屉--它与主布局重叠。

activity_set_main.xml

代码语言:javascript
复制
<?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:orientation="vertical"
    android:fitsSystemWindows="true"
    tools:openDrawer="start"
    >

<include
    layout="@layout/app_bar_set_main"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"

    />

<android.support.design.widget.NavigationView
    android:id="@+id/nav_view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:background="#000000"
    android:layout_marginTop="?android:attr/actionBarSize"
    android:layout_gravity="start"
    android:fitsSystemWindows="true"
    app:itemTextColor ="#FFFFFF"
    app:headerLayout="@layout/nav_header_set_main"
    app:menu="@menu/activity_set_main" />

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

app_bar_set_main.xml

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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:fitsSystemWindows="true"
    tools:context="com.example.pash.icas_nvod.setMain">

<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="wrap_content"
        android:background="?attr/colorPrimary"

       >
        <ImageView
            android:layout_width="220dp"
            android:layout_height="40dp"
            android:src="@drawable/bydesign_logo"
            android:layout_marginRight="80dp"
            android:id="@+id/toolbar_title" />
    </android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>

<include layout="@layout/content_set_main" />
</android.support.design.widget.CoordinatorLayout>

content_set_main.xml

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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/content_set_main_drawer"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:background="#EE7F22"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="com.example.pash.icas_nvod.setMain"
    >
    <ProgressBar
        android:id="@+id/login_progress"
        style="?android:attr/progressBarStyleLarge"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:visibility="gone" />
</RelativeLayout>

以上是我的xml文件无法使抽屉适合工具栏下。抽屉布局与主布局重叠。我怎么解决它..?我已经搜索了很多,但没有一个答案与我的problem.Thank你提前。

EN

回答 1

Stack Overflow用户

发布于 2017-10-27 13:42:38

您可以在您的android:layout_below="@+id/app_bar_set_main"中尝试DrawerLayout

您可以尝试将工具栏从抽屉布局中移出。因此,在我的项目中,我使用LinearLayout作为根布局。我试着用你的部件替换,希望它能帮上忙。

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">

<include
layout="@layout/app_bar_set_main"
android:layout_width="match_parent"
android:layout_height="wrap_content"

/>

<android.support.v4.widget.DrawerLayout 
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:fitsSystemWindows="true"
tools:openDrawer="start"
>

<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_below="@+id/app_bar_set_main" //Add this line also.
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#000000"
android:layout_marginTop="?android:attr/actionBarSize"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:itemTextColor ="#FFFFFF"
app:headerLayout="@layout/nav_header_set_main"
app:menu="@menu/activity_set_main" />

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


</LinearLayout>

编辑:,您还必须在工具栏下添加android:layout_below以适应您的抽屉。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46976186

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档