RecyclerView(或ListView)添加右侧侧边滑动滚动条进度条ScrollBar

上图先:
ScrollBar
这个东西叫ScrollBar,具体的动画形式是当用户上下或者左右滑动界面时,这个滑块会在需要显示的位置滑动。

以这张图为例,我们来做一个在屏幕右侧滑动的进度条。

首先,我们需要先画出它的shape——打开res资源文件夹底下的drawable文件夹,右击——New——Drawable Resource File,输入文件名,例如my_scrollBar_shape,其余默认。

此时就会出现一个默认为layer-list的xml资源文件。

这个文件的作用就是画出图片中的灰色渐变长矩形,也就是我们的滑块。

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

<!--    规定长宽-->
    <item
        android:width="@dimen/dp_4"
        android:height="@dimen/dp_94" >


<!--        绘制形状为矩形-->
        <shape android:shape="rectangle">


<!--            绘制梯度为线性,灰色渐变色-->
            <gradient
                android:type="linear"
                android:useLevel="true"
                android:startColor="#ffa0a8b9"
                android:endColor="#ff565d6b"
                android:angle="90"
                />

<!--            四个折角的位置-->
            <corners
                android:topLeftRadius="0dp"
                android:topRightRadius="0dp"
                android:bottomLeftRadius="0dp"
                android:bottomRightRadius="0dp"
                />

        </shape>
    </item>

</layer-list>

如代码,这个滑块我们已经做好了,可以在xml文件的design里面看到缩略图
my_scrollbar_shape

那么下一步,我们就需要把这个滑块应用到我们的界面上去,打开你需要添加右侧滑块的layout文件,找到RecyclerView或者ListView:

                    <androidx.recyclerview.widget.RecyclerView
                        android:id="@+id/my_rv"
                        android:layout_width="wrap_content"
                        android:layout_height="match_parent"
                        app:layout_constraintStart_toStartOf="parent"
                        app:layout_constraintTop_toTopOf="parent"

						//如下是我们添加的属性
                        android:scrollbars="vertical"    //垂直滑动
                        android:scrollbarThumbVertical="@drawable/my_scrollBar_shape"   //添加滑块形状
                        android:fadeScrollbars="false"    //无触控时不隐藏,如果设置为true就会隐藏
                        />

到这里就完成了。

参考博客:
RecyclerView自带的滚动条

Android Scrollbar理解

安卓listview滚动条高度设置

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

麻辣璐璐

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值