public class DragSurfaceView extends SurfaceView implements SurfaceHolder.Callback,Runnable{ private int screenW; //屏幕宽度 private int screenH; //屏幕高度 private float cx = 100; //默认X坐标 private float cy = 100; //默认Y坐标 private Bitmap mBitmap; private SurfaceHolder mSurfaceHolder = null; private Thread thread = null; public DragSurfaceView(Context context,@Nullable AttributeSet attrs) { super(context,attrs); mSurfaceHolder = getHolder(); mSurfaceHolder.addCallback(this); mBitmap=getBitmapResources(context,R.drawable.x1); thread=new Thread(this); } public static Bitmap getBitmapResources(Context context,int resId){ return BitmapFactory.decodeResource(context.getResources(),resId); } protected void myDraw() { //获取canvas实例 Canvas canvas = mSurfaceHolder.lockCanvas(); //将屏幕设置为白色 canvas.drawColor(Color.WHI
Android SurfaceView实现跟随手指移动的光标
最新推荐文章于 2021-05-25 14:09:06 发布