CollapsingToolbarLayout + TabLayout,奇怪的工具栏标题保证金 [英] CollapsingToolbarLayout + TabLayout, strange toolbar title margin
问题描述
我有我怀疑是有效的一个工具栏srange标题的行为。
崩溃:
扩展:
最奇怪的是,在
应用:titleMarginTop
块引用>不具有在标题放置任何影响。
下面是我的XML:
<?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
的xmlns:工具=http://schemas.android.com/tools
机器人:ID =@ + ID / main_content
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:fitsSystemWindows =真
工具:上下文=com.m360learning.app.activity.UserDetailsActivity>
< android.support.design.widget.AppBarLayout
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:fitsSystemWindows =真
机器人:主题=@风格/ ThemeOverlay.AppCompat.Dark.ActionBar> < android.support.design.widget.CollapsingToolbarLayout
机器人:ID =@ + ID / collapse_toolbar
机器人:layout_width =match_parent
机器人:layout_height =250dp
机器人:fitsSystemWindows =真
应用:contentScrim =?ATTR / colorPrimary
应用:layout_scrollFlags =滚动| exitUntilCollapsed> < RelativeLayout的
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:fitsSystemWindows =真
机器人:背景=@绘制/ background_navigation_drawer
应用:layout_collapseMode =视差>
< ImageView的
机器人:ID =@ + ID /头
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:fitsSystemWindows =真
机器人:scaleType =centerInside/> < / RelativeLayout的>
< android.support.v7.widget.Toolbar
机器人:ID =@ + ID /工具栏
机器人:layout_width =match_parent
机器人:layout_height =100dp
机器人:重力=顶
安卓了minHeight =?ATTR / actionBarSize
应用:layout_collapseMode =针
应用:popupTheme =@风格/ ThemeOverlay.AppCompat.Light /> < android.support.design.widget.TabLayout
机器人:ID =@ + ID /标签
机器人:layout_width =match_parent
机器人:layout_height =?ATTR / actionBarSize
机器人:layout_gravity =底
应用:tabIndicatorColor =@色/ colorAccent/> < /android.support.design.widget.CollapsingToolbarLayout> < /android.support.design.widget.AppBarLayout> < android.support.v4.view.ViewPager
机器人:ID =@ + ID /容器
机器人: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_margin =@扪/ fab_margin
机器人:SRC =@机器人:可绘制/ ic_dialog_email/>< /android.support.design.widget.CoordinatorLayout>任何帮助将大大AP preciated。
谢谢---编辑:
如果我设置工具栏的大小,以actionbarsize和它不改变扩展行为
------------最后编辑 - 修正
< android.support.design.widget.CoordinatorLayout的xmlns:机器人=http://schemas.android.com/apk/res/android
的xmlns:程序=http://schemas.android.com/apk/res-auto
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:fitsSystemWindows =真正的> < android.support.design.widget.AppBarLayout
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:fitsSystemWindows =真
机器人:主题=@风格/ ThemeOverlay.AppCompat.Dark.ActionBar> < android.support.design.widget.CollapsingToolbarLayout
机器人:ID =@ + ID / collapse_toolbar
机器人:layout_width =match_parent
机器人:layout_height =250dp
机器人:fitsSystemWindows =真
应用:contentScrim =?ATTR / colorPrimary
应用:layout_scrollFlags =滚动| exitUntilCollapsed> < RelativeLayout的
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:背景=@绘制/ background_navigation_drawer
机器人:fitsSystemWindows =真
机器人:ATTR / actionBarSizepaddingBottom会=
机器人:paddingEnd =30dp
机器人:paddingLeft =30dp
机器人:paddingRight =30dp
机器人:paddingStart =30dp
应用:layout_collapseMode =视差> ......
< / RelativeLayout的> < android.support.v7.widget.Toolbar
机器人:ID =@ + ID /工具栏
机器人:layout_width =match_parent
机器人:layout_height =?ATTR / actionBarSize
机器人:重力=顶
安卓了minHeight =?ATTR / actionBarSize
应用:layout_collapseMode =针
应用:popupTheme =@风格/ ThemeOverlay.AppCompat.Light
应用:titleMarginTop =15dp/> < /android.support.design.widget.CollapsingToolbarLayout>
< android.support.design.widget.TabLayout
机器人:ID =@ + ID /标签
机器人:layout_width =match_parent
机器人:layout_height =?ATTR / actionBarSize
机器人:layout_gravity =底
机器人:ATTR / colorPrimary背景=
应用:tabGravity =补
应用:tabIndicatorColor =#99FFFFFF
应用:tabIndicatorHeight =6DP
应用:tabMode =固定/> < /android.support.design.widget.AppBarLayout> < android.support.v4.view.ViewPager
机器人:ID =@ + ID /容器
机器人:layout_width =match_parent
机器人:layout_height =match_parent
应用:layout_behavior =@字符串/ appbar_scrolling_view_behavior/>
< /android.support.design.widget.CoordinatorLayout>
解决方案我觉得你TabLayout应该是你的CollapsingToolbarLayout外,同时还您AppBarLayout内:
< /android.support.design.widget.CollapsingToolbarLayout> < android.support.design.widget.TabLayout
机器人:ID =@ + ID /标签
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
应用:tabIndicatorColor =@色/ colorAccent/>< /android.support.design.widget.AppBarLayout>一个标签部分是应用栏的一部分,但是的不的工具栏的一部分。
I have a srange toolbar title behaviour that I doubt to be valid.
collapsed :
extended :
The strangest part is that the
app:titleMarginTop
does not have any effect on the title placement.
Here is my Xml :
<?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:id="@+id/main_content" android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true" tools:context="com.m360learning.app.activity.UserDetailsActivity"> <android.support.design.widget.AppBarLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:fitsSystemWindows="true" android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> <android.support.design.widget.CollapsingToolbarLayout android:id="@+id/collapse_toolbar" android:layout_width="match_parent" android:layout_height="250dp" android:fitsSystemWindows="true" app:contentScrim="?attr/colorPrimary" app:layout_scrollFlags="scroll|exitUntilCollapsed"> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true" android:background="@drawable/background_navigation_drawer" app:layout_collapseMode="parallax"> <ImageView android:id="@+id/header" android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true" android:scaleType="centerInside" /> </RelativeLayout> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="100dp" android:gravity="top" android:minHeight="?attr/actionBarSize" app:layout_collapseMode="pin" app:popupTheme="@style/ThemeOverlay.AppCompat.Light" /> <android.support.design.widget.TabLayout android:id="@+id/tabs" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" android:layout_gravity="bottom" app:tabIndicatorColor="@color/colorAccent" /> </android.support.design.widget.CollapsingToolbarLayout> </android.support.design.widget.AppBarLayout> <android.support.v4.view.ViewPager android:id="@+id/container" 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="end|bottom" android:layout_margin="@dimen/fab_margin" android:src="@android:drawable/ic_dialog_email" /> </android.support.design.widget.CoordinatorLayout>
Any help would be greatly appreciated. Thanks
---Edit : If I set the toolbar size to "actionbarsize"
And it doesn't change the expanded behaviour.
------------ FINAL EDIT -- CORRECTION
<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:fitsSystemWindows="true"> <android.support.design.widget.AppBarLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:fitsSystemWindows="true" android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> <android.support.design.widget.CollapsingToolbarLayout android:id="@+id/collapse_toolbar" android:layout_width="match_parent" android:layout_height="250dp" android:fitsSystemWindows="true" app:contentScrim="?attr/colorPrimary" app:layout_scrollFlags="scroll|exitUntilCollapsed"> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/background_navigation_drawer" android:fitsSystemWindows="true" android:paddingBottom="?attr/actionBarSize" android:paddingEnd="30dp" android:paddingLeft="30dp" android:paddingRight="30dp" android:paddingStart="30dp" app:layout_collapseMode="parallax"> ...... </RelativeLayout> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" android:gravity="top" android:minHeight="?attr/actionBarSize" app:layout_collapseMode="pin" app:popupTheme="@style/ThemeOverlay.AppCompat.Light" app:titleMarginTop="15dp" /> </android.support.design.widget.CollapsingToolbarLayout> <android.support.design.widget.TabLayout android:id="@+id/tabs" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" android:layout_gravity="bottom" android:background="?attr/colorPrimary" app:tabGravity="fill" app:tabIndicatorColor="#99FFFFFF" app:tabIndicatorHeight="6dp" app:tabMode="fixed" /> </android.support.design.widget.AppBarLayout> <android.support.v4.view.ViewPager android:id="@+id/container" android:layout_width="match_parent" android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior" /> </android.support.design.widget.CoordinatorLayout>
解决方案I think your TabLayout should be outside your CollapsingToolbarLayout while still inside your AppBarLayout:
</android.support.design.widget.CollapsingToolbarLayout> <android.support.design.widget.TabLayout android:id="@+id/tabs" android:layout_width="match_parent" android:layout_height="wrap_content" app:tabIndicatorColor="@color/colorAccent" /> </android.support.design.widget.AppBarLayout>
A tab section is part of the app bar, but not part of the tool bar.
这篇关于CollapsingToolbarLayout + TabLayout,奇怪的工具栏标题保证金的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!