-1

我从这里得到了以下代码,它绘制了一个垂直搜索栏:

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);
    }
}

此代码在 Android 2.3 上运行良好,但在 Android 4.2.2 中,拇指卡在滑块底部: 在此处输入图像描述

4

2 回答 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

于 2014-10-23T19:32:24.030 回答
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))))

于 2019-03-03T16:21:33.200 回答