我对 AppBarLayout 和 CollapsingToolbarLayout 有一些问题。这是目前发生的情况:
https://www.youtube.com/watch?v=z4yD8rmjSjU https://www.youtube.com/watch?v=z4yD8rmjSjU
向下滚动运动正是我想要的。然而,当我再次向上滚动时,橙色条应该立即出现(确实如此),但我希望 ImageView 仅在用户滚动到最顶部时才开始出现。谁能帮我达到这个效果?
这是我的布局 xml:
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="scroll|enterAlways|exitUntilCollapsed">
<TextView
android:text="ImageView"
android:textSize="20sp"
android:textColor="@android:color/white"
android:gravity="center"
android:layout_marginTop="56dp"
android:layout_width="match_parent"
android:layout_height="145dp"
app:layout_collapseMode="parallax"
android:background="#444"/>
<TextView
android:text="Top bar"
android:textColor="@android:color/white"
android:gravity="center_vertical"
android:paddingStart="16dp"
android:paddingEnd="16dp"
android:layout_width="match_parent"
android:layout_height="56dp"
android:background="#ff8000"
app:layout_collapseMode="pin"/>
</android.support.design.widget.CollapsingToolbarLayout>
<TextView
android:text="Bottom bar"
android:gravity="center_vertical"
android:paddingStart="16dp"
android:paddingEnd="16dp"
android:layout_width="match_parent"
android:textColor="@android:color/black"
android:layout_height="50dp"
android:background="#ddd"
app:layout_scrollFlags="enterAlways"/>
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_scrolling"/>
定制CoordinatorLayout
行为很难。您希望橙色条立即出现,但 ImageView 仅在内容滚动到顶部后出现,但这些视图属于一个父视图CollapsingToolbarLayout
两者都得到either你现在的行为or相反与enterAlwaysCollapsed
旗帜。我认为没有办法在不干扰 CoordinatorLayout/CollapsingToolbarLayout Java API 的情况下分离这些视图的行为。
如果更简单的行为不是一种选择,并且这里没有人指出一个简单的解决方案,我建议尝试一种相对较新的解决方案MotionLayout
而不是一起跳舞CollapsingToolbarLayout
内部,你最终会节省很多时间。一开始会有点困难,但它提供了明确的定制方法。这是一篇非常好的文章 https://blog.stylingandroid.com/motionlayout-collapsing-toolbar-part-1/展示了如何构建类似的用户体验CoordinatorLayout
但使用MotionLayout
。还有本文的第二部分 https://blog.stylingandroid.com/motionlayout-collapsing-toolbar-part-2/以及一些额外的定制。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)