我正在尝试实现一个具有固定值的离散滑块,但我唯一可以设置的是valueFrom、valueTo和stepSize。
这是我想要做的代码
<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的值)
发布于 2021-07-15 23:14:32
对我有用的解决方案是这个名为BubbleSeekBar的库。
步骤1-添加您的等级上的依赖项。
implementation "com.xw.repo:bubbleseekbar:3.20-lite"
步骤2-在XML上创建BubbleSeekBar并添加所需的属性。对于我的案例,下面的例子起了作用。
<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上声明的值数组。
bubbleSeekBar.setCustomSectionTextArray { sectionCount, array ->
array.clear()
for ((index, value) in resources.getStringArray(R.array.xxxx)
.withIndex()) {
array.put(index, value)
}
array
}
步骤4-您可以使用下面的方法捕获更改或设置值。
bubbleSeekBar.onProgressChangedListener
bubbleSeekBar.setProgress()
利卜很好,而且为我工作。要获得更多信息,请查看这个答案顶部的链接。
https://stackoverflow.com/questions/61896188
复制相似问题