How to get Coordinates on touch Event on bitmap not of Screen(如何在位图而不是屏幕上获取触摸事件坐标)
问题描述
问候,
如何获取位图的坐标而不是屏幕的坐标.通过 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 之后,您可以访问任何膨胀(活动)视图参数.例如.图像视图一个;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;
}
这篇关于如何在位图而不是屏幕上获取触摸事件坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在位图而不是屏幕上获取触摸事件坐标
基础教程推荐
- AdMob 广告未在模拟器中显示 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
