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

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

问题描述

映入眼帘,

我怎样才能得到屏幕的不是位图的坐标。通过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.

当然,当你在活动结束后的onCreate您可以查看在任何膨胀(活动)的意见参数。 为例。     ImageView的一个;     a.getPaddingBottom(); 像所有coordinats(左,右等...) 在此之后,你需要的ImageView的高度和宽度。 不,当你知道了意见位置,hegiht和宽度可以计算。

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天全站免登陆