一键事件使所有子视图进入按下状态

发布于 2024-10-16 12:39:06 字数 301 浏览 1 评论 0原文

毫无疑问,这是由我绝对非正统的布局引起的 - 我在 Activity 的 LinearLayout 中有按钮,该按钮由 ActivityGroup 放置到 Gallery 中。 ActivityGroup也是适配器实现,整体效果是全屏滑动、贴合面板。

这是有效的(实际上是一种享受),除了父布局上的触摸事件将所有按钮置于按下状态(并且任何释放都会删除该状态)。对单个按钮的触摸仅传递到该按钮。

这些按钮没有接收任何事件,它们只是改变状态。

我是否做了明显错误的事情?这是一个已知的错误吗?有解决方法吗?

任何见解将非常感激。

Doubtless this is caused by my decidedly unorthodox layout - I have buttons in a LinearLayout in an Activity which is placed by an ActivityGroup into a Gallery. The ActivityGroup is also the adapter implementation and the over-all effect is full-screen sliding, snapping panels.

This is working (a treat, actually) except that a touch event on the parent layout puts all the buttons into the pressed state (and any release removes the state). A touch on an individual button is only delivered to that button.

The buttons are not receiving any events, they're only changing state.

Have I done something obviously wrong? Is this a known bug and is there a work-around?

Any insights would be very much appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

怎言笑 2024-10-23 12:39:06

尽管这个问题很模糊,但它的解决方案可能对其他人有用,所以我会回答我自己的问题。

如前所述,我(错误)使用 Gallery 来提供 iPhone 上的滑动面板。当 Gallery 向其 Adapter 实现请求视图时,我通过返回 Activity 的顶级窗口来实现此目的。

Gallery 的典型使用会导致需要应用新闻事件的小视图 - 它更像是一个按钮,而不是一个面板。我们的使用意味着单个视图中有许多按钮,并且我们不希望在全局范围内应用新闻事件。

所以解决方法非常简单。我扩展了 Gallery 并故意破坏了 pointToPosition(int x, int y),每次都返回 INVALID_POSITION。 Gallery 仍然会执行预期的所有其他操作,但会跳过尝试将触地事件应用于除自身之外的任何元素(以准备滚动或快速滑动)。

我希望这对某人有价值。

As obscure as this problem is its solution may be of use to someone else, so I'll answer my own question.

As mentioned, I'm (mis)using the Gallery to provide a slidey-panel à la iPhone. I do this by returning the top level window of an Activity when the Gallery asks its Adapter implementation for a view.

Typical use of a Gallery would result in small Views to which it's desirable for the press event to be applied - it's more like a button then it is a panel. Our use means that there are many buttons in a single view and we don't want the press event to ever be applied globally.

So the work-around was very easy. I extended Gallery and deliberately broke pointToPosition(int x, int y), returning INVALID_POSITION every time. The Gallery still does everything else expected of it but skips trying to apply the touch down event to any elements but itself (to prepare itself to scroll or fling).

I hope this is of value to someone.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文