如何设置drawerlayout与协调布局工具栏的下方 [英] How to set drawerlayout below toolbar with coordinator layout
本文介绍了如何设置drawerlayout与协调布局工具栏的下方的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这样一个XML,当我告诉抽屉布局,它覆盖工具栏
,我想我下面的工具栏$ C我drawerlayout $ C>,我无法弄清楚如何做到这一点,我试过很多东西,我尝试了一整天。如何使用
CoordinatorLayout
与 DrawerLayout
不重叠的工具栏
?
这是我的动作条的风格:
<样式名称=AppTheme父=Theme.AppCompat.Light.NoActionBar>
<项目名称=colorPrimary> @彩色/ ColorPrimary< /项目>
<项目名称=colorPrimaryDark> @彩色/ ColorPrimaryDark< /项目>
<项目名称=colorAccent> @彩色/ ColorPrimary< /项目>
< /风格>
这是我的布局:
<?XML版本=1.0编码=UTF-8&GT?;
< android.support.v4.widget.DrawerLayout
机器人:ID =@ + ID / drawerLayout
的xmlns:机器人=http://schemas.android.com/apk/res/android
的xmlns:程序=http://schemas.android.com/apk/res-auto
机器人:layout_width =match_parent
机器人:layout_height =match_parent> < android.support.design.widget.CoordinatorLayout
机器人:layout_width =match_parent
机器人:layout_height =match_parent> < android.support.design.widget.AppBarLayout
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
应用:海拔=0dp> < android.support.v7.widget.Toolbar
机器人:ID =@ + ID /工具栏
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:背景=@彩色/ ColorPrimary
应用:layout_scrollFlags =滚动| enterAlways
应用:主题=@风格/ ThemeOverlay.AppCompat.Dark.ActionBar> <的TextView
机器人:ID =@ + ID / toolBarTv
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:文字=@字符串/ APP_NAME
机器人:文字颜色=@色/白
机器人:TEXTSIZE =18dp/> < /android.support.v7.widget.Toolbar> < /android.support.design.widget.AppBarLayout>
<的FrameLayout
机器人:ID =@ + ID /的FrameLayout
机器人:layout_width =match_parent
机器人:layout_height =match_parent
应用:layout_behavior =@字符串/ appbar_scrolling_view_behavior/> < android.support.design.widget.FloatingActionButton
机器人:ID =@ + ID / FAB
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_gravity =右|底
机器人:layout_marginBottom =10dp
机器人:layout_marginRight =10dp
应用:海拔=4DP
应用:fabSize =正常
应用:layout_behavior =com.frt.poppcar.utils.FabBehavior/> < /android.support.design.widget.CoordinatorLayout> <滚动型
机器人:ID =@ + ID / drawerList
机器人:layout_width =240dp
机器人:layout_height =match_parent
机器人:layout_gravity =左|启动
机器人:背景=@色/白> <的LinearLayout
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:方向=垂直> <的TextView
机器人:ID =@ + ID / mainTv
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:文字=@字符串/主
机器人:文字颜色=@彩色/五
机器人:TEXTSIZE =18dp/> < / LinearLayout中> < /滚动型>< /android.support.v4.widget.DrawerLayout>
解决方案
这对我的作品非常好.. u需要有协调布局父布局和设置的布局行为乌尔抽屉布局
<?XML版本=1.0编码=UTF-8&GT?;
< android.support.design.widget.CoordinatorLayout的xmlns:机器人=http://schemas.android.com/apk/res/android
的xmlns:程序=http://schemas.android.com/apk/res-auto
机器人:ID =@ + ID / main_content
机器人:layout_width =match_parent
机器人:layout_height =match_parent>< android.support.design.widget.AppBarLayout
机器人:ID =@ + ID / appbar
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:主题=@风格/ ThemeOverlay.AppCompat.Dark.ActionBar> < android.support.v7.widget.Toolbar
机器人:ID =@ + ID /工具栏
机器人:layout_width =match_parent
机器人:layout_height =?ATTR / actionBarSize
机器人:ATTR / colorPrimary背景=
应用:layout_scrollFlags =滚动| enterAlways
应用:popupTheme =@风格/ ThemeOverlay.AppCompat.Light/>< /android.support.design.widget.AppBarLayout><! - 制作工具栏滚动和隐藏对上攻包括这条线
应用:layout_behavior =@字符串/ appbar_scrolling_view_behavior - >
< android.support.v4.widget.DrawerLayout的xmlns:机器人=http://schemas.android.com/apk/res/android
的xmlns:程序=http://schemas.android.com/apk/res-auto
机器人:ID =@ + ID / drawer_layout
机器人:layout_marginTop =?ATTR / actionBarSize
机器人:layout_width =match_parent
机器人:layout_height =match_parent> <! - <包括布局=@布局/ navigation_drawer_content/> - >
<的FrameLayout
机器人:ID =@ + ID / content_frame
机器人: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 =开始
应用:headerLayout =@布局/ nav_header
应用:菜单=@菜单/ drawer_view/>< /android.support.v4.widget.DrawerLayout>
< /android.support.design.widget.CoordinatorLayout>
I have an xml like this, when I show drawer layout, It overlays Toolbar
, I want my drawerlayout below my Toolbar
, I cannot figure out how to do it, I tried lots of stuff and I tried it all day long. How can I use CoordinatorLayout
with DrawerLayout
without overlapping the Toolbar
?
This is my actionbar style:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/ColorPrimary</item>
<item name="colorPrimaryDark">@color/ColorPrimaryDark</item>
<item name="colorAccent">@color/ColorPrimary</item>
</style>
This is my layout:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawerLayout"
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.CoordinatorLayout
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"
app:elevation="0dp">
<android.support.v7.widget.Toolbar
android:id="@+id/toolBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/ColorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<TextView
android:id="@+id/toolBarTv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/app_name"
android:textColor="@color/white"
android:textSize="18dp"/>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="@+id/frameLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|bottom"
android:layout_marginBottom="10dp"
android:layout_marginRight="10dp"
app:elevation="4dp"
app:fabSize="normal"
app:layout_behavior="com.frt.poppcar.utils.FabBehavior"/>
</android.support.design.widget.CoordinatorLayout>
<ScrollView
android:id="@+id/drawerList"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="left|start"
android:background="@color/white">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/mainTv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/main"
android:textColor="@color/five"
android:textSize="18dp"/>
</LinearLayout>
</ScrollView>
</android.support.v4.widget.DrawerLayout>
解决方案
This works for me very well.. u need to have coordinator layout as parent layout and set layout behavior for ur drawer layout
<?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"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar
android:id="@+id/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.AppBarLayout>
<!-- to make toolbar scroll and hide towards upside include this line
app:layout_behavior="@string/appbar_scrolling_view_behavior"-->
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_marginTop="?attr/actionBarSize"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!--<include layout="@layout/navigation_drawer_content"/>-->
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="@layout/nav_header"
app:menu="@menu/drawer_view" />
</android.support.v4.widget.DrawerLayout>
</android.support.design.widget.CoordinatorLayout>
这篇关于如何设置drawerlayout与协调布局工具栏的下方的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文