package com.example.zhangshaohang1511b20171228; import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.util.AttributeSet; import android.view.MotionEvent; import android.view.View; /** * 姓名:${user} * 时间:${date} */ public class MyAdd extends View{ public float curreyX=100; public float curreyY=100; Context context=null; public MyAdd(Context context) { super(context); } public MyAdd(Context context, AttributeSet attrs) { super(context, attrs); } public MyAdd(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } public MyAdd(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); } @Override public boolean onTouchEvent(MotionEvent event) { curreyY=event.getY(); curreyX=event.getX(); invalidate(); return true; } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); Paint paint=new Paint(); paint.setColor(Color.RED); canvas.drawCircle(curreyX,curreyY,100,paint); } }
跟随手指移动小球
最新推荐文章于 2020-08-03 11:16:18 发布