前言
实现完了之前的手势九宫格之后,emm发现要的和我做的有点不一样。要的是这个
按键而非手势。
这个我因为之前实现了一个,所以这个做的时候不需要整理逻辑。文章写得很混乱。我删除了,重新贴一下代码吧。
实现
项目结构
指示器View
可以看到,主要就是画圆。然后重绘时要做的是填满圆。
然后通过update方法,让别人通知它更新
public class IphoneStepTipView extends View {
private static final String TAG = "IphoneStepTipView";
private Paint CirclePaint, fillPaint;
private float f_interval; //间隔
private float f_centerX, f_centerY, f_r; //中心位置
private float f_Lx; //最左边的圆心坐标
private int MODE;
private final int MODE_NEW = 0, MODE_UPDATE = 1, MODE_COMPLETE = 2;
private int selectSize; //当前输入了几个数字?
private int size = 4;
public IphoneStepTipView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public IphoneStepTipView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init();
}
private void init() {
Log.d(TAG, "init: ");
MODE = MODE_NEW;
CirclePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
CirclePaint.setColor(getContext().getColor(R.color.Palette147708_3));
CirclePaint.setStyle(Paint.Style.STROKE);
CirclePaint.setStrokeWidth(3);
fillPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
fillPaint.setColor(getContext().getColor(R.color.Palette147708_3));
fillPaint.setStyle(Paint.Style.FILL_AND_STROKE);
fillPaint.setStrokeWidth(3);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
if (MODE == MODE_NEW) {
Log.d(TAG, "新建");
float view_height = getMeasuredHeight();
float view_width = getMeasuredWidth();
float min_length = Math.min(view_height, view_width);
f_r = min_length / 4;
f_interval = f_r * 4; //两个圆的间隔是4r,加上圆有半径,所以中心点的距离是6r
float view_top = getTop();
float view_bottom = getBottom();
float view_left = getLeft();
float view_right = getRight();
f_centerY = (view_bottom - view_top) / 2;
f_centerX = (view_right - view_left) / 2;
f_Lx = f_centerX - 3 * f_r * (size - 1);
drawStroke(canvas);
} else