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 发布
本文介绍了一个自定义的ImageView类MyImageView,该类继承自Android的ImageView,并实现了触摸事件监听及画布上的圆形绘制功能。当按下触摸事件时开始绘制,释放或取消时停止绘制。
981

被折叠的 条评论
为什么被折叠?



