[英]hide Toolbar while scrolling
我有TabLayout
下方Toolbar
和下方的TabLayout
我有SearchLayout(CustomView)我需要隐藏Toolbar
,而滚动。 我尝试了很多方法,但没有发生 是否有相同的解决方案?
这是我的 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:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/background">
<android.support.design.widget.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<include
android:id="@+id/toolbar_search_screen"
layout="@layout/toolbar"
app:layout_scrollFlags="scroll|enterAlways" />
<android.support.design.widget.TabLayout
android:id="@+id/tab_layout"
style="@style/AppTabLayout"
android:layout_width="match_parent"
android:layout_height="@dimen/_45sdp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/tool_bar"
app:tabGravity="fill"
app:tabMode="fixed" />
</android.support.design.widget.AppBarLayout>
<RelativeLayout
android:id="@+id/search_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/_90sdp">
<include layout="@layout/search_layout" />
</RelativeLayout>
<android.support.v4.view.ViewPager
android:id="@+id/viewPager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="@dimen/_45sdp"
android:overScrollMode="never"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
只需向Toolbar
添加适当的滚动标志:
app:layout_scrollFlags="scroll|enterAlways"
以及滚动视图的适当行为(在您的情况下为SwipeRefreshLayout
和ViewPager
):
app:layout_behavior="@string/appbar_scrolling_view_behavior"
在 viewPager 视图中,它的子项必须是可滚动的,否则将无法工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.