Android的:如何添加在画布上的按钮或文本框 [英] android: how to add button or text box on canvas
问题描述
我想提出一个帆布并设置其背景是一个图像
我对canvas.Drawtext方法,它的工作原理perfctly好吗增加它的文字
现在我想这些文字可以点击,但我无法找到任何方法
i am making a canvas and setting its background which is an image i am adding text on it by canvas.Drawtext method which works perfctly alright now i want these text to be clickable but i couldnt find any method
我能想到的另一种方法是添加文本框画布上单击事件添加写
这些文本框,但无法找到与此相关的任何例子可以表明任何人做什么
the other method i could think of was to add text box on canvas add write on click event of these text box but could not find any example related to this can anybody suggest what to do
推荐答案
使用的onTouchEvent方法。下面是我用来找出如果用户的点击坐标是在矩形(又名按钮)列表的例子:
Use the onTouchEvent method. Here is an example I used for finding out if the user's click coordinates are in a List of rectangles (aka buttons):
@Override
public boolean onTouchEvent( MotionEvent event) {
super.onTouchEvent(event);
int x = (int)event.getX();
int y = (int)event.getY();
xStored = x; yStored=y;
if (event.getAction()==MotionEvent.ACTION_UP){
}else if(event.getAction()==MotionEvent.ACTION_DOWN){
System.out.println("Touching down!");
for(Rect rect : rectangles){
if(rect.contains(x,y)){
System.out.println("Touched Rectangle, start activity."+x+","+y);
invalidate();
}else{
}
}
}else if(event.getAction()==MotionEvent.ACTION_MOVE){
}
this.postInvalidate();
return true;
}
这篇关于Android的:如何添加在画布上的按钮或文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!