移动绘制跟随手指 [英] Moving drawable follow the finger

查看:136
本文介绍了移动绘制跟随手指的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个扩展视图类。

private class Draw2D extends View{
             public Draw2D(Context context) {
        super(context);
              }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        x = event.getX();
        y = event.getY();
        switch(event.getAction()){
        case MotionEvent.ACTION_MOVE:{

            break;
        }

        }
        return super.onTouchEvent(event);
    }


    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        Paint paint = new Paint();
        paint.setStyle(Paint.Style.FILL);
        paint.setColor(Color.WHITE);
        ShapeDrawable rectangle = 
        new ShapeDrawable(new RectShape());
        rectangle.getPaint().setColor(Color.GRAY);
        rectangle.getPaint().setStyle(Paint.Style.STROKE);
        rectangle.getPaint().setStrokeWidth(3);
        rectangle.setBounds(50, 30, 200, 150);
        rectangle.draw(canvas);
    }
}

我想动我的形状跟随手指在屏幕上。 我应该在 MotionEvent.ACTION_MOVE 写做我想要什么?

I want to moving my shape follow the finger on screen. What I should write in MotionEvent.ACTION_MOVE to do what I want?

推荐答案

这些的Youtube教程就是这样做的;

These Youtube tutorials do just this;

链接: https://buckysroom.org/videos.php?cat=6

只是看教程 71 ,的 72 和的 73 ,它应该工作

Just watch the tutorials 71, 72 and 73 and it should work.

这篇关于移动绘制跟随手指的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆