Android 折叠工具栏布局无法正常工作
更新:这发生在Android 5.0上,但在5.1上运行良好。我提交了这个问题(),看起来它将包含在库的下一个版本中Android 折叠工具栏布局无法正常工作,android,toolbar,android-design-library,android-collapsingtoolbarlayout,Android,Toolbar,Android Design Library,Android Collapsingtoolbarlayout,更新:这发生在Android 5.0上,但在5.1上运行良好。我提交了这个问题(),看起来它将包含在库的下一个版本中 所以我一直在玩新的,我遇到了一些问题。我想我已经解决了大部分问题,但我无法让它发挥作用。事实上,甚至连我的手机都不能正常工作 问题是,当工具栏展开时,图标太高。当它们倒塌时,它们就消失了。请参见屏幕截图 我正在运行5.0的Moto X上尝试这个。我知道这种情况会发生在更多的设备上,但实际上在其中一些设备上是有效的。这发生在你身上吗?有已知的解决方法吗 我发现这种现象将出现在a
所以我一直在玩新的,我遇到了一些问题。我想我已经解决了大部分问题,但我无法让它发挥作用。事实上,甚至连我的手机都不能正常工作 问题是,当工具栏展开时,图标太高。当它们倒塌时,它们就消失了。请参见屏幕截图 我正在运行5.0的Moto X上尝试这个。我知道这种情况会发生在更多的设备上,但实际上在其中一些设备上是有效的。这发生在你身上吗?有已知的解决方法吗
我发现这种现象将出现在android 5.0及以上版本中 这是我解决问题的方法:删除android.support.design.widget.CoordinatorLayout中的“android:fitsystemWindows=“true” 像这样:
<?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="@dimen/detail_backdrop_height"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
这是
com.android中的一个已知错误。支持:设计:22.2.0
。
它已经被修复,它被标记为谷歌问题下的未来版本。所以,让我们希望修复很快就会出来。
与问题的联系:
我用编程方式设置工具栏边距并设置工具栏安卓:fitsystemwindows=“true”来修复它 在activity_detail.xml布局上:
<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:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="@dimen/detail_backdrop_height"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:fitsSystemWindows="true">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginStart="48dp"
app:expandedTitleMarginEnd="64dp">
<ImageView
android:id="@+id/backdrop"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:fitsSystemWindows="true"
app:layout_collapseMode="parallax" />
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
android:fitsSystemWindows="true"
app:layout_collapseMode="pin" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingTop="24dp">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/card_margin">
<LinearLayout
style="@style/Widget.CardContent"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Info"
android:textAppearance="@style/TextAppearance.AppCompat.Title" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/cheese_ipsum" />
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/card_margin"
android:layout_marginLeft="@dimen/card_margin"
android:layout_marginRight="@dimen/card_margin">
<LinearLayout
style="@style/Widget.CardContent"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Friends"
android:textAppearance="@style/TextAppearance.AppCompat.Title" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/cheese_ipsum" />
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/card_margin"
android:layout_marginLeft="@dimen/card_margin"
android:layout_marginRight="@dimen/card_margin">
<LinearLayout
style="@style/Widget.CardContent"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Related"
android:textAppearance="@style/TextAppearance.AppCompat.Title" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/cheese_ipsum" />
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
<android.support.design.widget.FloatingActionButton
android:layout_height="wrap_content"
android:layout_width="wrap_content"
app:layout_anchor="@id/appbar"
app:layout_anchorGravity="bottom|right|end"
android:src="@drawable/ic_discuss"
android:layout_margin="@dimen/fab_margin"
android:clickable="true"/>
</android.support.design.widget.CoordinatorLayout>
结果:
固定在
com.android.support:design:22.2.1
删除android:fitsystemwindows=“true”将此行添加到折叠工具栏布局:app:layout\u scrollFlags=“scroll | exituntilclopsed”
它会起作用的您可能需要发布一些代码以获得任何帮助。@Ranjith我留下了一个指向“官方”repo()的链接,因为这个示例不起作用,但我尝试了repo的代码…该代码对我非常有效。@Ranjith是的,这就是我为什么要问的原因。查看屏幕截图,了解它在我的Moto X上的功能。我知道它在Nexus 7上也不起作用,但它似乎在Nexus 5上起作用。仅供参考,我刚刚将我的Moto X更新为5.1,现在工作正常。这是5.0的一个问题。删除fitsSystemWindows=“true”会使工具栏位置正确,但您无法将视图扩展到状态栏。我现在发现了。我认为这是android 5.0上的一个错误。我没什么好主意。对不起,我不知道这是安卓5.0上的bug还是这个库中的bug,但它在5.0上不起作用,在5.1上也起作用。我浪费了6个小时的黄金时间在这狗屎上,上帝保佑你@M星空是的,事实上是我提出了这个问题,因为我在这里没有得到任何好的答案。我推荐一点解释,而不是一句话的答案。
com.android.support:design:22.2.1