這個屬性本身沒有特別重要的功能,只是針對滑動做的一個動效,算是錦上添花的一個東西吧,
這個屬性是在Sdk 21之后添加的,故在21之前的版本上無法顯示,
1. 屬性設定后的效果:
在RecycleView可以滑動的時候,如果滑動到頂部或者底部,會顯示一個過度滑動的影片效果,這個屬性默認設定為always,可以手動修改,
2. 在xml中設定:
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:overScrollMode="always"
android:scrollbars="none"
tools:itemCount="5"
tools:listitem="@layout/item_rv" />
3. 在代碼中設定:
mode 共有三種模式可以設定,分別是:
-
OVER_SCROLL_ALWAYS( Always allow a user to over-scroll this view, provided it is a view that can scroll. )
-
OVER_SCROLL_IF_CONTENT_SCROLLS ( Allow a user to over-scroll this view only if the content is large enough to meaningfully scroll, provided it is a view that can scroll )
-
OVER_SCROLL_NEVER ( Never allow a user to over-scroll this view )
- Kotlin
mDataBinding.rv.overScrollMode = View.OVER_SCROLL_ALWAYS
- Java
recyclerView.setOverScrollMode(View.OVER_SCROLL_ALWAYS);
4. 修改EdgeEffect的顏色
如果不手動設定顏色,默認使用App的主題色,即 colorPrimary ,
如需修改顏色,可以通過設定style的方式來修改顏色,
<item name="android:colorEdgeEffect">@android:color/holo_red_light</item>
這里就是把顯示的顏色修改為紅色,
專案相關原始碼已經上傳github,
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/273742.html
標籤:其他
