-1

I got the following code from here which draws a vertical seekbar:

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.SeekBar;

public class VerticalSeekBar extends SeekBar {
    private static final int ROTATION_ANGLE = -90;

    private OnSeekBarChangeListener mOnSeekBarChangeListener;

    public VerticalSeekBar(final Context context) {
        super(context);
    }

    public VerticalSeekBar(final Context context, final AttributeSet attrs, final int defStyle) {
        super(context, attrs, defStyle);
    }

    public VerticalSeekBar(final Context context, final AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected final void onSizeChanged(final int width, final int height, final int oldWidth, final int oldHeight) {
        super.onSizeChanged(height, width, oldHeight, oldWidth);
    }

    @Override
    protected final synchronized void onMeasure(final int widthMeasureSpec, final int heightMeasureSpec) {
        super.onMeasure(heightMeasureSpec, widthMeasureSpec);
        setMeasuredDimension(getMeasuredHeight(), getMeasuredWidth());
    }

    @Override
    protected final void onDraw(final Canvas c) {
        c.rotate(ROTATION_ANGLE);
        c.translate(-getHeight(), 0);

        super.onDraw(c);
    }

    @Override
    public final void setOnSeekBarChangeListener(final OnSeekBarChangeListener l) {
        mOnSeekBarChangeListener = l;
        super.setOnSeekBarChangeListener(l);
    }

    @SuppressLint("ClickableViewAccessibility")
    @Override
    public final boolean onTouchEvent(final MotionEvent event) {
        if (!isEnabled()) {
            return false;
        }

        switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:
            setProgress(getMax() - (int) (getMax() * event.getY() / getHeight()));
            mOnSeekBarChangeListener.onStartTrackingTouch(this);
            break;

        case MotionEvent.ACTION_MOVE:
            setProgress(getMax() - (int) (getMax() * event.getY() / getHeight()));
            break;

        case MotionEvent.ACTION_UP:
            setProgress(getMax() - (int) (getMax() * event.getY() / getHeight()));
            mOnSeekBarChangeListener.onStopTrackingTouch(this);
            break;

        case MotionEvent.ACTION_CANCEL:
            mOnSeekBarChangeListener.onStopTrackingTouch(this);
            break;

        default:
            break;
        }

        return true;
    }

    @Override
    public final void setProgress(final int progress) {
        super.setProgress(progress);
        onSizeChanged(getWidth(), getHeight(), 0, 0);
    }
}

This code worked fine on Android 2.3, but in Android 4.2.2 the thumb stuck in bottom of slider bar: enter image description here

2 Answers 2

0

Maybe it's because of the zeros in

onSizeChanged(getWidth(), getHeight(), 0, 0);

It's one of the few things, which are changed by hand.

Further I noticed that the code is working on 4.4.4 and 4.1.2.

/Edit/

This package is working: http://560b.sakura.ne.jp/android/VerticalSlidebarExample.zip Thanks to Andro Selva

2
  • See this for changes introduced in 4.2: developer.android.com/about/versions/android-4.2.html
    – Price
    Oct 23, 2014 at 19:44
  • 1
    Welcome to SO, you seem to be new. I'd therefore suggest you read the How to answer introduction as your current answer seems to be more a guess than an actual answer and is finished by a question which is unusual for an Q&A style board like SO.
    – Sim
    Oct 23, 2014 at 19:50
0

ipwcheat:sets(CustomInterface(round((show_circle,true)(y,574)(x,1651)(zoom,3.0)(btn_type,focus)(running,true))seekbar((vertical,false)(flipped,false)(y,1005)(x,635)(zoom,5.0)(running,true))))

1
  • Please format your code and while this code may answer the question, providing additional context regarding how and/or why it solves the problem would improve the answer's long-term value. Mar 3, 2019 at 18:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.