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
//    }
}
相关推荐
漏刻有时6 小时前
PHP GeoJSON转PNG地图渲染程序开发笔记、源码解读、问题复盘与整改方案
android·笔记·php
-SOLO-7 小时前
解决VMware 显示比例被重置的问题
android
alexhilton7 小时前
探究Android Views、Flutter和Compose如何渲染你的UI
android·kotlin·android jetpack
Lesile10 小时前
Android:Hilt框架入门 · 在ViewUI和ComposeUI下的应用
android·android jetpack
用户4238162290710 小时前
Android 16 WebView 页面顶部挖孔/通知栏不能显示UI问题排查
android
weixin_7275356211 小时前
Loop 已死,Graph 新生:AI 工作流的范式革命
android·人工智能·rxjava
严同学正在努力12 小时前
从备份到恢复:我用 30 分钟恢复了误删的核心业务表
android·java·数据库·ai
梦想三三12 小时前
LangChain Output Parser 实战:从字符串到结构化数据的完整指南
android·服务器·langchain·github·uv
爱笑鱼15 小时前
Binder(八):远端进程死了,BinderProxy 为什么还能收到通知?
android
Android-Flutter15 小时前
Kotlin 冷流与热流详解
android·kotlin