Search code examples
androidandroid-layoutandroid-seekbarandroid-vertical-seekbar

Android Seekbar values not going to negative on some devices


I am using multiple vertical seekbars in my Android application using android:rotation= "270". I have set the min and max of these seekbars let's say -50 to 50. Now the seekbars and working fine on all of my devices and emulator but it isn't going to negative values on some devices. If I set the android:progress to -20 then then seekbar shows it at -20 when the app starts, but once I move it to positive values and then try to move back, it get stuck on 0 and doesn't go down any further.


Solution

  • There is no straight way of doing this, however there is a trick. If you want your seek-bar to go from -50 to +50 with default value 0, simply create a seek-bar with a text field with it such that

    android:min="0"; 
    android:min="100";
    android:progress="50";
    

    Now set the text of text-field such that when the value at seek-bar is 50, value at text field is 0. So now when the seek-bar is at 0, the text field would represent as -50. Similarly you can change the value to wherever you want to use in your program.