public class MyImageView extends ImageView {
private float pointX = 0f;
private float pointY = 0f;
private int count = 1;
private Paint paint;
private boolean isDraw = false;
public MyImageView(Context context) {
super(context);
init();
}
public MyImageView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public JImageView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init();
}
/**
* 初始化
*/
private void init() {
paint = new Paint();
paint.setAntiAlias(true);
paint.setColor(0x35333333);
}
@Override
protected void onDraw(Canvas canvas) {
if (isDraw) {
count += 2;
canvas.drawCircle(pointX, pointY, count, paint);
postInvalidateDelayed(16);
}
super.onDraw(canvas);
}
@Override
@SuppressLint("ClickableViewAccessibility")
public boolean onTouchEvent(MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
isDraw = true;
pointX = event.getX();
pointY = event.getY();
postInvalidate();
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_MOVE:
case MotionEvent.ACTION_CANCEL:
isDraw = false;
count = 1;
break;
}
return true;
}
}
仿Android 5.0按钮点击效果
最新推荐文章于 2021-05-26 10:19:47 发布