2

I was looking for an implementation of a vertical SeekBar and found this: How can I get a working vertical SeekBar in Android?

It works fine. However I want it to be "reversed", e.i min is on top and max is at the bottom. Is this possible? I've tried to rotate it in different degrees but with no success.

Community
  • 1
  • 1
henrikpersson
  • 338
  • 2
  • 9

1 Answers1

2

I have worked on your problem and came out with a solution. I have made us of the answer here. I have modified the code little bit and have achieved your goal. Here is the link to my project,

https://github.com/AndroSelva/Vertical-SeekBar-Android

Just a little modification in the onDraw(),

protected void onDraw(Canvas c) {
    c.rotate(90);
    c.translate(0, -getWidth());

    super.onDraw(c);
}

and onTouchEvent(),

switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:
        case MotionEvent.ACTION_MOVE:
        case MotionEvent.ACTION_UP:
            int i=0;
            i=getMax() - (int) (getMax() * event.getY() / getHeight());
            setProgress(100-i);
            Log.i("Progress",getProgress()+"");
            onSizeChanged(getWidth(), getHeight(), 0, 0);
            break;

        case MotionEvent.ACTION_CANCEL:
            break;
    }
Community
  • 1
  • 1
Andro Selva
  • 53,910
  • 52
  • 193
  • 240