日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

android 上滑隐藏view,Android CoordinatorLayout + AppBarLayout(向上滚动隐藏指定的View)

發(fā)布時間:2025/3/21 Android 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android 上滑隐藏view,Android CoordinatorLayout + AppBarLayout(向上滚动隐藏指定的View) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

在新的Android Support Library里面,新增了CoordinatorLayout, AppBarLayout等.

實現(xiàn)的效果:?向下滾動RecylerView,Tab會被隱藏,向上滾動RecylerView,Tab恢復(fù)出現(xiàn).這么做的好處在于,用戶能有更多的空間位置去看列表里面的內(nèi)容.

實現(xiàn)步驟:

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:orientation="vertical">

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:orientation="vertical">

android:id="@+id/third_activity_toolbar"

android:layout_width="match_parent"

android:layout_height="?attr/actionBarSize"/>

android:id="@+id/tab_layout"

android:layout_width="match_parent"

android:layout_height="wrap_content"

app:layout_scrollFlags="scroll|enterAlways"

app:tabIndicatorColor="@color/medium_blue"

app:tabSelectedTextColor="@color/medium_blue"

app:tabTextAppearance="@style/TabText"

app:tabTextColor="@color/gray_text"/>

android:id="@+id/viewpager"

android:layout_width="match_parent"

android:layout_height="wrap_content"

app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

1) 首先需要用CoordinatorLayout包住AppBarLayout;

2) 頂部區(qū)域的View都放在AppBarLayout里面;

3) AppBarLayout外面,CoordinatorLayout里面,放一個帶有可滾動的View.如上的例子,放的是ViewPager,而ViewPager里面是放了RecylerView的,即是可以滾動的View.

4) 在AppBarLayout里面的View,通過app:layout_scrollFlags屬性來控制,滾動時候的表現(xiàn).其中有4種Flag的類型.

scroll: this flag should be set for all views that want to scroll off the screen - for views that do not use this flag, they’ll remain pinned to the top of the screen

enterAlways: this flag ensures that any downward scroll will cause this view to become visible, enabling the ‘quick return’ pattern

enterAlwaysCollapsed: When your view has declared a minHeight and you use this flag, your View will only enter at its minimum height (i.e., ‘collapsed’), only re-expanding to its full height when the scrolling view has reached it’s top.

exitUntilCollapsed: this flag causes the view to scroll off until it is ‘collapsed’ (its minHeight) before exiting

上面的例子種用的是?scroll和 enterAlways.

Scroll 表示向下滾動時,這個View會被滾出屏幕范圍直到隱藏.

enterAlways 表示向上滾動時,這個View會隨著滾動手勢出現(xiàn),直到恢復(fù)原來的位置.

5) 在可以滾動的View上設(shè)置屬性?app:layout_behavior.

該屬性的值實際上是一個完整的class名字,而上面例子中的 @string/appbar_scrolling_view_behavior 是Android Support Library 定義后的值,可以被直接使用.

這個Behavior的class是真正控制滾動時候View的滾動行為.我們也可以繼承Behavior這個class去實現(xiàn)特有的滾動行為.

6) 代碼部分,只需要實現(xiàn)RecylerView的邏輯就可以了.

來源:https://www.cnblogs.com/wingyip/p/4604472.html

總結(jié)

以上是生活随笔為你收集整理的android 上滑隐藏view,Android CoordinatorLayout + AppBarLayout(向上滚动隐藏指定的View)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。