如何在触摸事件中移动ShapeDrawable在画布 [英] How to Move a ShapeDrawable in Canvas on Touch Events

查看:131
本文介绍了如何在触摸事件中移动ShapeDrawable在画布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现绘图应用程序在Android中。其中,用户应能选择和移动的绘制的形状。
目前,我有静态得出了一些rects和文字在我的画布:

I am trying to implement a Drawing Application in Android. Where the user should be able to select and move the drawn shapes.
Currently i have statically drawn some rects and text on my Drawing Canvas:

        View mDrawingCanvas = new View(mContext) 
        {
            ShapeDrawable rectangle;
            @Override
            public boolean isFocused() {
                // TODO Auto-generated method stub
                Log.d(TAG, "View's On focused is called !");
                return super.isFocused();
            }

            @Override
            public boolean onTouchEvent(MotionEvent event) {
                // TODO Auto-generated method stub

                return super.onTouchEvent(event);
            }

            @Override
            protected void onDraw(final Canvas canvas) {
                super.onDraw(canvas);
                // Work out current total scale factor
                // from source to view

                final float scale = mSourceScale*(float)getWidth()/(float)mSize.x;

                Paint paint = new Paint();
                paint.setStyle(Paint.Style.FILL);
                paint.setColor(Color.WHITE);

                //Custom View
                rectangle = new ShapeDrawable(new RectShape());
                rectangle.getPaint().setColor(Color.GRAY);
                rectangle.getPaint().setStyle(Paint.Style.FILL_AND_STROKE);
                rectangle.getPaint().setStrokeWidth(3);
                rectangle.setBounds((int)(50*scale), (int)(30*scale), (int)(200*scale), (int)(150*scale));
                rectangle.draw(canvas);

                rectangle.getPaint().setColor(Color.BLUE);
                rectangle.getPaint().setStyle(Paint.Style.FILL_AND_STROKE);
                rectangle.getPaint().setStrokeWidth(3);
                rectangle.setBounds((int)(200*scale), (int)(200*scale), (int)(400*scale), (int)(350*scale));
                rectangle.draw(canvas);
            }
        };

我要选择(利用所选形状边界)和移动图形绘制在画布的onTouch事件。
可有一个人请指导我有关这一点,任何帮助是高度鸭preciated。

I want to select (draw borders on the selected shape) and move the drawn Shapes in onTouch events of the drawing canvas.
Can some one please guide me about this, any help is Highly Appreciated.

推荐答案

这个答案已经证明了形状运动方法,我一直在寻找。
而我现在的问题就解决了​​。这个链接是:
拖动和移动画在画布上的圆

This answer has demonstrated the Shape Moving Methodology that i was looking for.
And my problem is solved now. The Link is :
Drag and move a circle drawn on canvas

这篇关于如何在触摸事件中移动ShapeDrawable在画布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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