Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我OnTouchListener为我的布局实现了包括其中的每一个layout/widget,并且我成功地检索了滑动的方向和widget/layout接收滑动的 ID。
OnTouchListener
layout/widget
widget/layout
我的问题是,如果用户在两个或更多不同的对象上滑动,例如他在两个按钮上从左向右滑动,第一个按钮接收到触摸事件,我只得到那个按钮的 id。如何检索进行滑动的对象的所有 ID(与滑动键盘功能相同)?
有没有办法通过触摸事件的 X 和 Y 获取用户在滑动移动期间触摸的每个对象的 ID?
谢谢。
如果我目前了解您的问题,那么您可以执行以下操作。
在按钮的 OnTouch 方法中使用下面的代码。
LinearLayout mLinearlayout=(LinearLayout) v.getParent();
通过这种方式,您将获得按钮父视图,现在执行从父视图获取其他视图的过程。这里我LinearLayout 仅用于示例,因为我有LinearLayout我的父视图Button View。
LinearLayout
Button
View