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
//    }
}
相关推荐
bobuddy1 小时前
平台总线(platform bus)
android
plainGeekDev1 小时前
libs 目录 → Gradle 依赖管理
android·java·kotlin
帅次2 小时前
Android 高级工程师面试:Flutter Widget 体系 近1年高频追问 20 题
android·flutter·面试·element·widget·setstate·renderobject
帅次2 小时前
Android 高级工程师面试:Jetpack 核心 近1年高频追问 20 题
android·面试·协程·jetpack·stateflow·lifecycle
爱笑鱼3 小时前
Handler(四):Handler 卡顿怎么定位?从 Slow delivery 到 Slow dispatch
android
九皇叔叔3 小时前
RHEL9.8 配置本地镜像仓库
android·java·缓存
私人珍藏库4 小时前
[Android] 聊天记录微备份 -聊天记录备份+本地数据备份
android·人工智能·app·软件·多功能
私人珍藏库5 小时前
[Android] PocketPal -本地离线AI助手+大模型部署神器
android·人工智能·app·软件·多功能
listening7775 小时前
HarmonyOS 6.1 跨端实战:用ArkUI-X把电商App同时跑在Android/iOS上
android·ios·harmonyos
爱笑鱼6 小时前
Handler(三):主线程、HandlerThread、Binder 线程到底怎么区分?
android