首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >固定号码的Android滑块

固定号码的Android滑块
EN

Stack Overflow用户
提问于 2020-05-19 16:34:25
回答 3查看 3K关注 0票数 2

我正在尝试实现一个具有固定值的离散滑块,但我唯一可以设置的是valueFrom、valueTo和stepSize。

这是我想要做的代码

代码语言:javascript
运行
复制
<com.google.android.material.slider.Slider
        android:id="@+id/slider"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:padding="8dp"
        app:tickColor="@color/colorSecondaryLight"
        app:tickColorActive="@color/colorSecondary" />

有办法在滑块上设置固定值吗?(使用2、5、10、25、50和100的值)

EN

Stack Overflow用户

回答已采纳

发布于 2021-07-15 23:14:32

对我有用的解决方案是这个名为BubbleSeekBar的库。

步骤1-添加您的等级上的依赖项。

代码语言:javascript
运行
复制
implementation "com.xw.repo:bubbleseekbar:3.20-lite"

步骤2-在XML上创建BubbleSeekBar并添加所需的属性。对于我的案例,下面的例子起了作用。

代码语言:javascript
运行
复制
<com.xw.repo.BubbleSeekBar
        android:id="@+id/bubbleSeekBar"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        app:bsb_auto_adjust_section_mark="true"
        app:bsb_hide_bubble="true"
        app:bsb_min="2"
        app:bsb_section_count="5"
        app:bsb_section_text_position="below_section_mark"
        app:bsb_seek_by_section="true" />

步骤3-由于我需要自定义选项,所以我在onCreate上初始化了string.xml上声明的值数组。

代码语言:javascript
运行
复制
bubbleSeekBar.setCustomSectionTextArray { sectionCount, array ->
            array.clear()
            for ((index, value) in resources.getStringArray(R.array.xxxx)
                .withIndex()) {
                array.put(index, value)
            }
            array
        }

步骤4-您可以使用下面的方法捕获更改或设置值。

代码语言:javascript
运行
复制
bubbleSeekBar.onProgressChangedListener
bubbleSeekBar.setProgress()

利卜很好,而且为我工作。要获得更多信息,请查看这个答案顶部的链接。

票数 1
EN
查看全部 3 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61896188

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档