Android中绘图的问题 [英] The problem with drawing in Android

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

问题描述

问题是正方形一直在画,我想在我们放开手指的同时画.我想看广场,但我不知道如何解决,您有什么建议吗?

这是我的代码:

The problem is that the square draws all the time, and I want to draw as we let go of finger. I want to see the square, but I don''t know how to resolve it, do you have any suggestions?

This is my code:

@Override
public boolean onTouchEvent(MotionEvent event)
{
    float x = event.getX();
    float y = event.getY();
    switch (event.getAction())
    {
        case MotionEvent.ACTION_DOWN:
                    if (square) {
                    	rect = new Rect();
                    	mX = x;
                        mY = y;
                	invalidate();
		    }
                    draw_mod = true;
                    break;
                case MotionEvent.ACTION_MOVE:                    
                    if (square && draw_mod) {
                    	rect.set((int)mX, (int)mY, 
                                 (int)event.getX(), (int)event.getY());
                    	mCanvas.drawRect(rect, mPaint);
                	invalidate();
		     }
                     break;
                case MotionEvent.ACTION_UP
                        draw_mod = false;
                	break;
            }
            return true;
        }:

推荐答案

当您需要注册触摸事件时,您不仅可以绘制图形.

我假设
You can''t just do the drawing when you need to register the touch event.

I''m assuming that
rect

是成员变量,但它不像其他变量那样遵循命名约定.如果它不是私有成员变量,则将其设为一个.

您将需要覆盖要绘制的视图的

is a member variable, but it doesn''t follow the naming convention like your other variables. If it isn''t a private member variable, then make it one.

You will need to override the

onDraw()

方法.

method of the view that you want to draw on.

protected void onDraw (Canvas canvas)
{
    super.onDraw(canvas);

    //Now draw your rect ontop of whatever was just drawn.
    canvas.drawRect(rect, mPaint);
}



上传了 ImageShack.us

大多数作品,只有我在绘画方面有问题.我不希望这种效果如图片所示.

Uploaded with ImageShack.us

Most of works, only I have problem with drawing. I do not want this effect as the picture.


这篇关于Android中绘图的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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