我试图在touch of Image上获得x,y坐标,并且我想要执行一些 *** 作.所以,任何人都可以告诉我如何触摸图像的x,y坐标.提前致谢.
我的代码 –
public class MovableObject extends ImageVIEw implements OntouchListener{ Bitmap myBmp; Paint myPaint = new Paint(); int MoveX = 0; public MovableObject(Context context,int moveObject,Bitmap myBmp) { super(context); super.setClickable(true); this.myBmp = myBmp; myPaint.setcolor(color.WHITE); this.MoveX = moveObject; setontouchListener(this); } @OverrIDe protected voID onDraw(Canvas canvas) { super.onDraw(canvas); canvas.drawBitmap(myBmp, MoveX, 100, myPaint); } @OverrIDe public boolean ontouch(VIEw v, MotionEvent event) { switch (event.getAction() & MotionEvent.ACTION_MASK) { case MotionEvent.ACTION_DOWN: System.out.println("down...."+event.getX()+" "+event.getY()); case MotionEvent.ACTION_MOVE: } return true; }}
通过这个我得到x,y坐标,我点击,但我想得到x,y当我点击我的图像.
解决方法:
MoveX – It is the starting x co-ordinate of your vIEw.
MoveY –
It is the starting y co-ordinate of your vIEw.
imgHeiht – It is the
Height of the Image;
imgWIDth – It is the WIDth of the Image;event.getX()- It is the actual position of your X co-ordinate.
event.getY()- It is the actual position of your Y co-ordinate.
if(MoveX <= event.getX() && event.getX()<= (MoveX+imgWIDth) && (MoveY <= event.getY() && (event.getY() <= MoveY+imgHeight))){ System.out.println("down...."+event.getX()+" "+event.getY()); }
这可能对你有所帮助.
总结以上是内存溢出为你收集整理的android – 如何使用OnTouch()检查图像是否被触摸全部内容,希望文章能够帮你解决android – 如何使用OnTouch()检查图像是否被触摸所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)