Android:可点击布局内的嵌套链接
场景如下:
- 我有一个
RalativeLayout
,其中包含ImageView
和一些TextView
。 - 这些
TextViews
内有“链接化”元素,例如 URL、电话号码等。 - 单击链接会导致各种操作,单击 ImageView 也会触发一些操作。
- 现在 - 我希望将外部 onClick 附加到
RelativeLayout
的整个区域,这样如果用户单击布局内的任何位置(但在图像和链接之外),那么它会执行另一个操作
Right现在我有 layout#onClick
、image#onClick
,嵌入的链接由 Linkify 处理。图像和链接点击工作可靠,但布局点击大约有 50% 的时间被捕获,我想这会让用户感到沮丧到流泪。你们可以建议一些提高可靠性的技巧吗?如果不是,从最佳可用性的角度来看,实现这一目标的好方法是什么?
Here's scenario:
- I have a
RalativeLayout
holdingImageView
and fewTextViews
. - There are "linkified" elements inside these
TextViews
such as URLs, phone numbers, etc. - Clicking on the links result in various actions, also clicking on ImageView triggers some action too.
- Now - I want to have outer onClick attached to the complete area of
RelativeLayout
in such way that if user clicks on any spot withing the layout (but outside of the image and links) then it executes another action
Right now I have layout#onClick
, image#onClick
, and embedded links are processed by Linkify. Image and links clicks are working reliably but clicks on layout are captured about 50% of the time and I suppose would frustrate users to the point of tears. Any tricks that you guys can suggest to improve reliability? And if not what would be a good way of achieving this from the best usability standpoint?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
既然没有人给出答案,至少我可以分享我对解决方案的想法。基本上,我决定不对抗重叠的点击处理程序,而是从在父级上启用
onClick
开始。然后,当父控件检测到单击时,它会关闭自己的焦点并让其他控件处理单击。我还添加了“关闭”按钮,该按钮仅在展开父视图时才可见,单击该按钮会折叠父视图并将焦点放回到父视图中。如果您知道更好的解决方案,请告诉我
Since no one came out with answer at least I can share my thoughts about the solution. Basically I decided not to fight overlapping click handlers and instead, start with
onClick
enabled on the parent. Then, when the parent detects the click it turns it's own focus off and lets other controls take care of clicks. I also added "Off" button that is visible only when parent is expanded and clicking on that collapses the parent and puts the focus back into the parent view.Let me know if you know better solution