Android Seekbar Flipped Horizontally
With the Android SeekBar, you can normally drag the thumb to the left or to the right and the yellow progress color is to the left of the thumb. I want the exact opposite, essentia
Solution 1:
After fiddling around with some code this is what I got and it seems to work pretty well. Hopefully it will help someone else in the future.
publicclassReversedSeekBarextendsSeekBar {
publicReversedSeekBar(Context context) {
super(context);
}
publicReversedSeekBar(Context context, AttributeSet attrs) {
super(context, attrs);
}
publicReversedSeekBar(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@OverrideprotectedvoidonDraw(Canvas canvas) {
floatpx=this.getWidth() / 2.0f;
floatpy=this.getHeight() / 2.0f;
canvas.scale(-1, 1, px, py);
super.onDraw(canvas);
}
@OverridepublicbooleanonTouchEvent(MotionEvent event) {
event.setLocation(this.getWidth() - event.getX(), event.getY());
returnsuper.onTouchEvent(event);
}
}
This was thrown together with the help of these two questions:
Solution 2:
Have you tried seekbar.setRotation( 180 )? It flips the seekbar 180 degrees and is upside down, meaning left side is max, right side is 0 with the color on the right of the thumb. No need to create a custom seekbar this way.
Solution 3:
You should look into making a custom progress bar. Considering what you want to do, you already have the images you need in the Android SDK. I'd extract them and edit them accordingly. Here's a tutorial to help get you started.
Solution 4:
Have you tried setting this in xml
android:rotationY="180"
Solution 5:
This should fix a few issues with @mhenry answer
classReverseSeekBar : SeekBar {constructor(context: Context) : super(context) {
init()
}
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) {
init()
}
constructor(context: Context, attrs: AttributeSet?, defStyle: Int) : super(context, attrs, defStyle) {
init()
}
var first = trueoverridefunonTouchEvent(event: MotionEvent): Boolean {
event.setLocation(this.width - event.x, event.y)
returnsuper.onTouchEvent(event)
}
overridefungetProgress(): Int {
return max - super.getProgress() + min
}
overridefunsetProgress(progress: Int) {
super.setProgress(max - progress + min)
}
overridefunonDraw(canvas: Canvas?) {
if (first) {
first = falseval old = progress
progress = min + max - progress
super.onDraw(canvas)
progress = old
} elsesuper.onDraw(canvas)
}
privatefuninit() {
rotation = 180f
}
}
Post a Comment for "Android Seekbar Flipped Horizontally"