Android RecycleView 条目进入和滑出屏幕的渐变阴影效果

RecycleView 上下左右 条目进入滑出屏幕时的阴影渐变效果,Rv自带了这种效果

1. xml需要配置的属性

  • android:fadingEdgeLength="40dp" 阴影长度
  • android:requiresFadingEdge="horizontal" 阴影方向
ini 复制代码
<com.qianrun.voice.common.view.LiveCommentRecycleView
    android:fadingEdgeLength="40dp"
    android:requiresFadingEdge="horizontal"
    android:layout_marginEnd="30dp"
    android:layout_marginStart="10dp"
    android:layout_marginTop="13dp"
    app:layout_constraintTop_toBottomOf="@+id/magic_indicator"
    app:layout_constraintStart_toEndOf="@+id/tv_1"
    app:layout_constraintEnd_toStartOf="@+id/tv_check_all"
    android:layout_width="0dp"
    android:layout_height="wrap_content"

    android:id="@+id/rv_user"/>

2:自定义Rv 处理指定阴影不展示

kotlin 复制代码
class LiveCommentRecycleView : RecyclerView {

    constructor(context: Context) : super(context){
        if(isInEditMode)
            return
    }

    constructor(context: Context, attrs: AttributeSet) : super(context, attrs){
        if(isInEditMode)
            return
    }

    constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr){
        if(isInEditMode)
            return
    }

    /**
     * 隐藏 bottom 阴影
     * @return Float
     */
    override fun getBottomFadingEdgeStrength(): Float {
        return 0f
    }
    /**
     * 隐藏 左边阴影
     * @return Float
     */
    override fun getLeftFadingEdgeStrength(): Float {
        return  0f
    }

//    /**
//     * 隐藏 右边阴影
//     * @return Float
//     */
//    override fun getRightFadingEdgeStrength(): Float {
//        return  0f
//    }
//    /**
//     * 隐藏 顶部阴影
//     * @return Float
//     */
//    override fun getTopFadingEdgeStrength(): Float {
//        return  0f
//    }
}
相关推荐
whysqwhw1 小时前
Android Jetpack 中 ViewModel 的全面解析
android
2501_916007474 小时前
iPhone查看App日志和系统崩溃日志的完整实用指南
android·ios·小程序·https·uni-app·iphone·webview
稻草人不怕疼4 小时前
Android 渲染机制小结
android
JokerX4 小时前
基于 Kotlin + Jetpack Compose 的完整电商开源项目分享
android
佳哥的技术分享4 小时前
android APT技术
android
2501_915918417 小时前
iOS 抓不到包怎么办?全流程排查思路与替代引导
android·ios·小程序·https·uni-app·iphone·webview
_祝你今天愉快8 小时前
Java-JVM探析
android·java·jvm
飞天卡兹克8 小时前
forceStop流程会把对应进程的pendingIntent给cancel掉
android
Monkey-旭16 小时前
Android Bitmap 完全指南:从基础到高级优化
android·java·人工智能·计算机视觉·kotlin·位图·bitmap
Mike_Wuzy21 小时前
【Android】发展历程
android