布局片段重叠的工具栏 [英] Layout for Fragment overlapping Toolbar

查看:242
本文介绍了布局片段重叠的工具栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我更换/把我的片段中的FrameLayout这个code一DrawerLayout内:

 <?XML版本=1.0编码=UTF-8&GT?;
  < android.support.v4.widget.DrawerLayout
  的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
  的xmlns:程序=htt​​p://schemas.android.com/apk/res-auto
  的xmlns:工具=htt​​p://schemas.android.com/tool​​s
  机器人:ID =@ + ID / drawer_layout
  机器人:layout_width =match_parent
  机器人:layout_height =match_parent
  机器人:fitsSystemWindows =真
  工具:openDrawer =开始>
<包括
    布局=@布局/ app_bar_base
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent/>
<的FrameLayout
    机器人:ID =@ + ID /容器
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent/>
<! - 抽屉里的物品 - >
< android.support.design.widget.NavigationView
    机器人:ID =@ + ID / nav_view
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =match_parent
    机器人:layout_gravity =开始
    机器人:fitsSystemWindows =真
    应用:headerLayout =@布局/ nav_header_base
    应用:菜单=@菜单/ activity_base_drawer/> < /android.support.v4.widget.DrawerLayout>

app_bar_base.xml 包含一个工具栏和FAB:

 <?XML版本=1.0编码=UTF-8&GT?;
    < android.support.design.widget.CoordinatorLayout
     的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
     的xmlns:程序=htt​​p://schemas.android.com/apk/res-auto
     的xmlns:工具=htt​​p://schemas.android.com/tool​​s
     机器人:layout_width =match_parent
     机器人:layout_height =match_parent
     机器人:fitsSystemWindows =真
     工具:上下文=BaseActivity。>< android.support.design.widget.AppBarLayout
    机器人:layout_width =match_parent
    机器人:ID =@ + ID / appBar
    机器人:layout_height =WRAP_CONTENT
    机器人:主题=@风格/ AppTheme.AppBarOverlay>    < android.support.v7.widget.Toolbar
        机器人:ID =@ + ID /工具栏
        机器人:layout_width =match_parent
        机器人:layout_height =?ATTR / actionBarSize
        机器人:ATTR / colorPrimary背景=
        应用:popupTheme =@风格/ AppTheme.PopupOverlay/>< /android.support.design.widget.AppBarLayout>< android.support.design.widget.FloatingActionButton
    机器人:ID =@ + ID / FAB
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_gravity =底部|结束
    机器人:layout_margin =@扪/ fab_margin
    机器人:SRC =@机器人:可绘制/ ic_dialog_email/>< /android.support.design.widget.CoordinatorLayout>

当我跑我的应用程序,这是结果:

在这里输入的形象描述

正如你所看到的,碎片的布局重叠Toolbar.How我能解决这个问题?

我试过把两个工具栏和一个的FrameLayout里面的LinearLayout像这样的:

 <的LinearLayout
    机器人:layout_width =match_parent
    机器人:方向=垂直
    机器人:layout_height =match_parent>    <的LinearLayout
        机器人:layout_width =match_parent
        机器人:layout_height =match_parent>
        <包括
            布局=@布局/ app_bar_base
            机器人:layout_width =match_parent
            机器人:layout_height =match_parent/>    < / LinearLayout中>    <的FrameLayout
        机器人:ID =@ + ID /容器
        机器人:layout_width =match_parent
        机器人:layout_height =match_parent/>
< / LinearLayout中>

但随后的FrameLayout得到隐藏的。


解决方案

 请不要忘了添加应用程序:layout_behavior =@字符串/ appbar_scrolling_view_behavior你的内容布局< android.support.design.widget.CoordinatorLayout
   的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
   的xmlns:程序=htt​​p://schemas.android.com/apk/res-auto
   机器人:layout_width =match_parent
   机器人:layout_height =match_parent>      < android.support.design.widget.AppBarLayout
         机器人:layout_width =match_parent
         机器人:layout_height =WRAP_CONTENT
         机器人:主题=@风格/ ThemeOverlay.AppCompat.Dark.ActionBar>           < android.support.v7.widget.Toolbar
              机器人:layout_width =match_parent
              机器人:layout_height =?ATTR / actionBarSize
              机器人:ATTR / colorPrimary背景=
              应用:layout_scrollFlags =滚动| enterAlways
              应用:popupTheme =@风格/ ThemeOverlay.AppCompat.Light/>           < android.support.design.widget.TabLayout
              机器人:layout_width =match_parent
              机器人:layout_height =WRAP_CONTENT/>
       < /android.support.design.widget.AppBarLayout>       < android.support.v4.view.ViewPager
             机器人:layout_width =match_parent
             机器人:layout_height =match_parent
             应用:layout_behavior =@字符串/ appbar_scrolling_view_behavior/>< /android.support.design.widget.CoordinatorLayout>

Am replacing/placing my Fragments in a FrameLayout inside of a DrawerLayout with this code:

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


<FrameLayout
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />


<!--drawer items-->
<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:headerLayout="@layout/nav_header_base"
    app:menu="@menu/activity_base_drawer" />

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

app_bar_base.xml contains a Toolbar and a FAB:

<?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=".BaseActivity">

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:id="@+id/appBar"
    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.design.widget.AppBarLayout>



<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|end"
    android:layout_margin="@dimen/fab_margin"
    android:src="@android:drawable/ic_dialog_email" />

</android.support.design.widget.CoordinatorLayout>

When I run my app, this is the result:

As you can see, the layout for the fragment overlaps the Toolbar.How can I fix this?

I've tried placing both the Toolbar and FrameLayout inside a LinearLayout like this:

 <LinearLayout
    android:layout_width="match_parent"
    android:orientation="vertical"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <include
            layout="@layout/app_bar_base"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

    </LinearLayout>

    <FrameLayout
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</LinearLayout>

but then the FrameLayout gets hidden.

解决方案

Please do not forget to add app:layout_behavior="@string/appbar_scrolling_view_behavior" to your content layout

<android.support.design.widget.CoordinatorLayout  
   xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:app="http://schemas.android.com/apk/res-auto"
   android:layout_width="match_parent"
   android:layout_height="match_parent">

      <android.support.design.widget.AppBarLayout
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

           <android.support.v7.widget.Toolbar
              android:layout_width="match_parent"
              android:layout_height="?attr/actionBarSize"
              android:background="?attr/colorPrimary"
              app:layout_scrollFlags="scroll|enterAlways"
              app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

           <android.support.design.widget.TabLayout
              android:layout_width="match_parent"
              android:layout_height="wrap_content" />
       </android.support.design.widget.AppBarLayout>

       <android.support.v4.view.ViewPager
             android:layout_width="match_parent"
             android:layout_height="match_parent"
             app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

</android.support.design.widget.CoordinatorLayout>

这篇关于布局片段重叠的工具栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆