项目中需要用到一个竖直的SeekBar
简单搜索了一下,要么不能用,要么没开源(鄙视,安卓系统都是开源的,你一个简单的demo也不开源,恶心),最好的一个是有bug的
不过没关系,bug好说,改一下就行了
废话不多说,
代码直接用就行
下面本来代码的出处已经忘记了,
核心改动是 原来的setOnSeekBarChangeListener =》 setOnChangedListener 用这个方法就是正常的,原始方法的开始与停止回调函数没作用
import android.content.Context;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.ViewConfiguration;
import android.view.ViewParent;
import android.widget.ProgressBar;
import android.widget.SeekBar;
/**
* 使用 setOnChangedListener 完美
**/
public class VerticalSeekBar extends SeekBar {
<span style="white-space:pre"> </span>private boolean mIsDragging;
<span style="white-space:pre"> </span>private float mTouchDownY;
<span style="white-space:pre"> </span>private int mScaledTouchSlop;
<span style="white-space:pre"> </span>private boolean isInScrollingContainer = false;
<span style="white-space:pre"> </span>public boolean isInScrollingContainer() {
<span style="white-space:pre"> </span>return isInScrollingContainer;
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>public void setInScrollingContainer(boolean isInScrollingContainer) {
<span style="white-space:pre"> </span>this.isInScrollingContainer = isInScrollingContainer;
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>/**
<span style="white-space:pre"> </span> * On touch, this offset plus the scaled value from the position of the
<span style="white-space:pre"> </span> * touch will form the progress value. Usually 0.
<span style="white-space:pre"> </span> */
<span style="white-space:pre"> </span>float mTouchProgressOffset;
<span style="white-space:pre"> </span>public VerticalSeekBar(Context context, AttributeSet attrs, int defStyle) {
<span style="white-space:pre"> </span>super(context, attrs, defStyle);
<span style="white-space:pre"> </span>mScaledTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>public VerticalSeekBar(Context context, AttributeSet attrs) {
<span style="white-space:pre"> </span>super(context, attrs);
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>public VerticalSeekBar(Context context) {
<span style="white-space:pre"> </span>super(context);
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>@Override
<span style="white-space:pre"> </span>protected void onSizeChanged(int w, int h, int oldw, int oldh) {
<span style="white-space:pre"> </span>super.onSizeChanged(h, w, oldh, oldw);
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>@Override
&