如何在位图而不是屏幕上的触摸事件上获取坐标 [英] How to get Coordinates on touch Event on bitmap not of Screen

查看:20
本文介绍了如何在位图而不是屏幕上的触摸事件上获取坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问候,

如何获取位图的坐标而不是屏幕的坐标.屏幕坐标通过 event.getX(),event.getY() 方法获取,但不获取位图坐标.请帮助任何人.

How can I get the Coordinates of the Bitmap not of the screen. Screen Coordinates got by event.getX(),event.getY() methods but not getting coordinates of the bitmap. Please help anyone.

推荐答案

无法直接获取位图的坐标.你需要自己计算.使用ImageView的位置,你可以处理它.

You can't get the coordinates of the bitmap directly. You need to calculate to yourself. Use the position of the ImageView, and with that you can handle it.

当然,当您在 Activity onCreate 之后,您可以访问任何膨胀(活动)视图参数.例如.ImageView a;a.getPaddingBottom();像所有坐标(左右等...)在此之后,您需要 ImageView 的高度和宽度.不,当您知道视图位置、高度和宽度时,您就可以计算了.

Of course, when you are after Activity onCreate you can acces to any inflated (active) views parameter. Exemple. ImageView a; a.getPaddingBottom(); Like all coordinats (left right etc...) After this you need the Height and Width of the ImageView. Nah, when you know the views position, hegiht and width you can calculate.

示例:

final ImageView iv_YourImage = (ImageView) findViewById(R.id.iv_imageview);
public boolean onTouch(View v, MotionEvent event){
int topParam =  iv_YourImage.getPaddingTop();
 int rightParam =  iv_YourImage.getPaddingRight();
int maxTopParam = topParam+iv_YourImage.getMaxHeight();
int maxRightParam = rightParam + iv_YourImage.getMaxWidth();
 if(event.getX>topParam&&event.getX<maxTopParam){
    //the x coordinate is in your image... do the same to Y
 }
return true;
}

这篇关于如何在位图而不是屏幕上的触摸事件上获取坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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