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
//    }
}
相关推荐
豆豆豆大王4 小时前
Android 数据持久化(SharedPreferences)
android
Paper_Love4 小时前
RK3588-android-reboot命令内核调用流程
android
介一安全4 小时前
【Frida Android】基础篇12:Native层hook基础——调用原生函数
android·网络安全·逆向·安全性测试·frida·1024程序员节
2501_916008895 小时前
用多工具组合把 iOS 混淆做成可复用的工程能力(iOS混淆|IPA加固|无源码混淆|Ipa Guard|Swift Shield)
android·开发语言·ios·小程序·uni-app·iphone·swift
Zach_yuan6 小时前
程序地址空间
android·linux·运维·服务器
带电的小王6 小时前
llama.cpp:Android端测试Qwen2.5-Omni
android·llama.cpp·qwen2.5-omni
明道源码6 小时前
Android Studio 代码编辑区域的使用
android·ide·android studio
小墙程序员8 小时前
从隐私协议了解Android App到底获取了哪些信息
android
小墙程序员8 小时前
Android 5 到 16 期间 service 的发展
android
Android小码家8 小时前
Android8.0+Camera2编译&烧录&源码研习
android·framework