如何在位图而不是屏幕上获取触摸事件坐标

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;
}

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

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How to target newer versions in .gitlab-ci.yml using auto devops (java 11 instead of 8 and Android 31 instead of 29)(如何在.gitlab-ci.yml中使用自动开发工具(Java 11而不是8,Android 31而不是29)瞄准较新的版本)
Android + coreLibraryDesugaring: which Java 11 APIs can I expect to work?(Android+core LibraryDesugering:我可以期待哪些Java 11API能够工作?)
How to render something in an if statement React Native(如何在If语句中呈现某些内容Reaction Native)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
Using Firebase Firestore in offline only mode(在仅脱机模式下使用Firebase FiRestore)
Crash on Google Play Pre-Launch Report: java.lang.NoSuchMethodError(Google Play发布前崩溃报告:java.lang.NoSuchMethodError)