当滑动列表需要两侧阴影时,可以设置RecyclerView的FadingEdge属性:
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fadingEdgeLength="50dp"
android:fadingEdge="horizontal"
android:requiresFadingEdge="horizontal" />
fadingEdgeLength参数为阴影的长度,当API Level>14 应该使用requiresFadingEdge
这样RecyclerView两端都会有阴影
如果仅需左侧或者是右侧需要 需要重写View类的获取阴影长度的方法
将不需要阴影的部分返回参数设置为0即可
import android.content.Context
import android.util.AttributeSet
import androidx.recyclerview.widget.RecyclerView
class FadingEdgeRecyclerView : RecyclerView {