[英]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.