ImageView 的特定部分可点击
关于让 ImageView 占据整个屏幕并使其仅部分可点击有什么想法?我想我可以扩展 ImageView 类并重写它的 ontouch 方法,这将允许我根据 x 和 y 检测触摸。我能看到的唯一问题是在不同的分辨率下触摸可能无法映射到正确的区域。我想我可以检测分辨率并找出某种方法将 x 和 y 映射到正确的区域。我觉得必须有一个更简单的方法。还有人有其他想法吗?
What are some ideas about having an ImageView that takes up the whole screen and making only parts of it clickable? I was thinking that I could extend the ImageView class and override its ontouch method which would allow me to detect touches based on an x and y. The only problem I can see with this is on different resolutions the touches might not map to the correct areas. I suppose I could then detect the resolution and figure out some way to map the x and y to the correct areas. I feel like there must be an easier way though. Does anyone have any other ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如何使用RelativeLayout 在 ImageView 顶部创建带有所需点击侦听器的透明视图。您可以使用 xml 将这些“热点”放置在您想要的相对于图像的位置,并定义布局,以便“热点”视图在以不同分辨率显示时与图像一起正确缩放。
How about creating transparent views with your desired click listeners on top of the ImageView using a RelativeLayout. You can use the xml to place those "hotspots" where you would like them relative to your image and define the layout so the "hotspot" view scale properly along with the image when displayed on different resolutions.
如果“热点”形状不太复杂,您可以动态分割图像,设置单独的点击侦听器并以某种方式重新合并可绘制对象,使它们看起来连续。不过我确实更喜欢格雷格的方法。
If the 'hotspot' shapes are not too complex, you could dynamically split the image, setup individual clicklisteners and re-merge the drawables in a way for them to appear contiguous. I do like Gregg's method more though.