Search code examples
androidseekbar

How to make a vertical SeekBar in Android?


Can a SeekBar be vertical? I am not very good at UI design, so how can I make the SeekBar more beautiful, please give me some templates and examples.


Solution

  • Here is a very good implementation of vertical seekbar. Have a look.

    http://560b.sakura.ne.jp/android/VerticalSlidebarExample.zip

    And Here is my own implementation for Vertical and Inverted Seekbar based on this

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

    protected void onDraw(Canvas c) {
        c.rotate(-90);
        c.translate(-getHeight(),0);
    
        super.onDraw(c);
    }
    
    @Override
    public boolean onTouchEvent(MotionEvent event) {
        if (!isEnabled()) {
            return false;
        }
    
        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
            case MotionEvent.ACTION_MOVE:
            case MotionEvent.ACTION_UP:
                int i=0;
                i=getMax() - (int) ((getMax()-getMin()) * event.getY() / getHeight());
                setProgress(i);
                Log.i("Progress",getProgress()+"");
                onSizeChanged(getWidth(), getHeight(), 0, 0);
                break;
    
            case MotionEvent.ACTION_CANCEL:
                break;
        }
        return true;
    }