Discrete SeekBar

放肆的年华 提交于 2020-01-11 04:40:06

问题


I am trying to create a discrete seek bar for an Android app.

I know I can set max and min values for a SeekBar (my ideal solution would be the Click example below) but I want the bar to move up and down the slider at particular intervals - every 10 in my case. So the only options available on the SeekBar would be;

  • 20
  • 30
  • 40
  • 50
  • 60
  • 70

Is it possible to define specific values to a standard Android SeekBar or at least change the intervals between items. If not, then would it be possible with a custom seekbar? I have not found anything online which addresses this (not for Android at least - frustrating as its a recognised component in the Google Material design guidelines).


回答1:


Check this link If you want to implement discrete seekbar with number of gaps without using third party library then use style property of seekbar.

<SeekBar
     android:id="@+id/sb"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:max="10"
     android:thumb="@drawable/ic_location"
     android:theme="@style/Widget.AppCompat.SeekBar.Discrete" />




回答2:


The Android SeekBar cannot set intervals, but you can set the maximum value to 10 so that the range is [0, 10], and whenever you want to get a value from it, multiply the SeekBar's value by 10, so you can "simulate" having intervals of 0, 10, 20, 30, ...



来源:https://stackoverflow.com/questions/34912297/discrete-seekbar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!