我一直在开发绘图应用程序,我遇到了一些问题:手指绘图的意思已经完成,但现在我需要制作任何允许用户在{{1上写一个公共文本标签的东西}}。所以,请看看我的代码:
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;
}
}
课程中。所以,现在我需要允许用户编写一个简单的文本。我认为我可以通过长按来实现 - 用户长按一下,键盘打开,用户可以输入文字。但它不起作用!我的日志中没有看到任何字符串。
请告诉我有关我的问题的建议,或者告诉我如何才能实现我的需求。
答案 0 :(得分:0)
我非常确定OnTouchListener
在return true
时消耗了触摸事件。试试return super.onTouch(v, event)
。