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.
在我的应用程序中,我使用 GridView 实现了类似画廊的视图。我想根据用户的选择手动更改 GridView 中的列数。我可以通过提供任何按钮或菜单选项来更改它。我想对 Zoom / Pinch 操作做同样的事情,例如,如果有人尝试缩放 GridView,它应该减少列数,如果尝试 Pinch 则增加相同的列数。为了实现这一点,我尝试覆盖 onTouch 事件,但它既不流畅也不如预期。如果有人知道或知道如何实现这一目标,请告诉我。
这并不容易。
首先我会试试这个:
在 GridView 上面放一个普通的 View(即这个 View 与 GridView 处于相同的位置,并且具有相同的宽度和高度)。
覆盖这个普通视图的 onTouchEvent。如果您检测到捏缩放,请进行特殊处理(更改 GridView 的列)。如果您没有检测到 Pinch Zoom,让 onTouchEvent 返回 false(未处理),让触摸事件冒泡到底层 GridView。
诀窍在于正确识别 Pinch Zoom 而不会弄乱 GridView 的默认触摸行为。