想整个双向的进度条,就是可以选取播放范围的。
像这样:
20170905165905.png
然而官方控件里只有单向的。不要慌,我们自己画一个。
绘制一个进度条主要是三方面。1.样式,2.尺寸,3.操作监听。
完整代码来一遍:
注释基本上就把原理说明了一下。
package util;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.drawable.Drawable;
import android.support.v4.content.ContextCompat;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import com.example.qzd.utildemo.R;
import java.math.BigDecimal;
/**
* 双向滑块的进度条(区域选择)
*/
public class SeekRangeBar extends View {
private Context _context;
private static final int CLICK_ON_LOW = 1; //手指在前滑块上滑动
private static final int CLICK_ON_HIGH = 2; //手指在后滑块上滑动
private static final int CLICK_IN_LOW_AREA = 3; //手指点击离前滑块近
private static final int CLICK_IN_HIGH_AREA = 4; //手指点击离后滑块近
private static final int CLICK_OUT_AREA = 5; //手指点击在view外
private static final int CLICK_INVAILD = 0;
private static final int[] STATE_NORMAL = {};
private static final int[] STATE_PRESSED =
{android.R.attr.state_pressed,android.R.attr.state_window_focused,};
private static int mThumbMarginTop = 0; //滑动块顶部离view顶部的距离
private static int mTextViewMarginTop = 0; //当前滑块文字距离view顶部距离
private Drawable hasScrollBarBg; //滑动条滑动后背景图
private Drawable notScrollBarBg; //滑动条未滑动背景图
private Drawable mThumbLow; //前滑块
private Drawable mThumbHigh; //后滑块
private int mScollBarWidth; //控件宽度 = 滑动条宽度 + 滑动块宽度
private int mScollBarHeight; //控件高度
private int mThumbWidth; //滑动块直径
private double mOffsetLow = 0; //前滑块中心坐标
private double mOffsetHigh = 0; //后滑块中心坐标
private int mDistance=0; //总刻度是固定距离 两边各去掉半个滑块距离
private int mFlag = CLICK_INVAILD; //手指按下的类型
private double defaultScreenLow = 0; //默认前滑块位置百分比
private double defaultScreenHigh = 100; //默认后滑块位置百分比
private OnSeekBarChangeListener mBarChangeListener;
private boolean editable=false;//是否处于可编辑状态
private int miniGap=5;//AB的最小间隔
private double progressLow;//起点(百分比)
private double progressHigh;//终点
public Seek