2

我一直在开发绘图应用程序,但遇到了一些问题:手指绘图的平均值已经完成,但现在我需要制作任何允许用户在View. 所以,请看我的代码:

public class PainterView extends View implements DrawingListener {

    private Painter painter;

    private Bitmap bitmap;
    private Paint bitmapPaint;
    private Path path;
    private Paint paint;

    public PainterView(Context context, Painter painter) {

        super(context);
        this.painter=painter;
        this.setOnTouchListener(new OnTouchListener() {

            public boolean onTouch(View v, MotionEvent event) {
                float x = event.getX();
                float y = event.getY();

                switch (event.getAction()) {
                    case MotionEvent.ACTION_DOWN:
                        PainterView.this.painter.touchStart(x, y);
                        break;
                    case MotionEvent.ACTION_MOVE:
                        PainterView.this.painter.touchMove(x, y);
                        break;
                    case MotionEvent.ACTION_UP:
                        PainterView.this.painter.touchUp();
                        break;
                }

                return true;
            }

        });
        this.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
                Log.e("event", "click");
            }

        });
        this.setOnLongClickListener(new OnLongClickListener() {
            public boolean onLongClick(View v) {
                Log.e("event", "long");
                return true;
            }

        });  
    }

    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        super.onSizeChanged(w, h, oldw, oldh);
    }

    protected void onDraw(Canvas canvas) {
        if (bitmap!=null) {
            canvas.drawBitmap(bitmap, 0, 0, bitmapPaint);
            canvas.drawPath(path, paint);
        } 
    }

    public void onPictureUpdate(Bitmap bitmap, Paint bitmapPaint, Path path, Paint paint) {

        this.bitmap=bitmap;
        this.bitmapPaint=bitmapPaint;
        this.path=path;
        this.paint=paint;
        invalidate();
    }

    public void setPainter(Painter painter) {
        this.painter=painter;
    }
}

这是绘图的代码;绘画的过程在Painter课堂上。所以,现在我需要允许用户写一个简单的文本。我认为我可以通过长按来做到这一点——用户长按,键盘打开,用户可以输入文本。但它不起作用!我的日志中没有看到任何字符串。

请告诉我有关我的问题的建议或一些想法,我如何才能意识到我需要什么。

4

1 回答 1

0

我很确定OnTouchListener当你使用触摸事件时return true。试试return super.onTouch(v, event)

于 2012-06-15T12:58:45.657 回答