I'm looking for a way to implement a minimum value in my SeekBar and also have the option to increment decimal numbers. For example, currently my SeekBar's minimum is set to 0, but I need it to start at the value 0.2. Also, I would like to have the functionality to be able to have the user select a number from 0.2 to 10.0 at a .1 precision so they can choose the numbers 5.6 or 7.1.
Here are the style attributes for my SeekBar:
<style name="SeekBar">
<item name="android:paddingLeft">30dp</item>
<item name="android:paddingRight">30dp</item>
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_marginTop">0dp</item>
<item name="android:layout_marginBottom">0dp</item>
<item name="android:max">10</item>
<item name="android:progress">1</item>
</style>
The values that can be used for the progress are limited to values between zero and some max value that we choose. We can however scale these values with arithmetic operations. Lets for example set the max value to 200 in the XML-file. Then change the java code in the following way.
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
sliderValueTW.setText(Float.toString((float)(progress-100)/10));
}
The result is that the slider appears to the user to be going from -10.0 to 10.0 with increments of 0.1 units.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With