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
//    }
}
相关推荐
砖厂小工2 小时前
用 GLM + OpenClaw 打造你的 AI PR Review Agent — 让龙虾帮你审代码
android·github
张拭心3 小时前
春节后,有些公司明确要求 AI 经验了
android·前端·人工智能
张拭心3 小时前
Android 17 来了!新特性介绍与适配建议
android·前端
Kapaseker5 小时前
Compose 进阶—巧用 GraphicsLayer
android·kotlin
黄林晴6 小时前
Android17 为什么重写 MessageQueue
android
阿巴斯甜1 天前
Android 报错:Zip file '/Users/lyy/develop/repoAndroidLapp/l-app-android-ble/app/bu
android
Kapaseker1 天前
实战 Compose 中的 IntrinsicSize
android·kotlin
xq95271 天前
Andorid Google 登录接入文档
android
黄林晴1 天前
告别 Modifier 地狱,Compose 样式系统要变天了
android·android jetpack
冬奇Lab2 天前
Android触摸事件分发、手势识别与输入优化实战
android·源码阅读