Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Discrete SeekBar

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

Example

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).

like image 213
Jonny Wright Avatar asked Jan 20 '16 23:01

Jonny Wright


People also ask

What is discrete SeekBar?

In Android Discrete SeekBar is just an advancement of progressBar just like the SeekBar, the only difference in SeekBar and discrete SeekBar being that in discrete SeekBar, we can only set the value only to discrete values like 1, 2, 3, and so on.

What is SeekBar?

In Android, SeekBar is an extension of ProgressBar that adds a draggable thumb, a user can touch the thumb and drag left or right to set the value for current progress. SeekBar is one of the very useful user interface element in Android that allows the selection of integer values using a natural user interface.

What is SeekBar in player?

Well according to android.developers.com, A SeekBar is an extension of ProgressBar that adds a draggable thumb. The user can touch the thumb and drag left or right to set the current progress level or use the arrow keys. Placing focusable widgets to the left or right of a SeekBar is discouraged.

What is SeekBar in video?

If you're not familiar with the SeekBar component, it's a component used to seek through media files – you'll likely see one within the media player in your device.


2 Answers

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" />

enter image description here

like image 156
Nilesh Senta Avatar answered Sep 28 '22 03:09

Nilesh Senta


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, ...

like image 23
RogueBaneling Avatar answered Sep 28 '22 03:09

RogueBaneling