安卓的MediaController拦截所有其他触摸事件事件、MediaController

2023-09-12 10:30:40 作者:装出你的高调丶

我的应用程序的上半部分有一个 VideoView 的MediaController 在它之下。下半部分是与某些按钮的图像。而的MediaController 是可见的,下面的按钮是不能点击。这就像,而的MediaController 是可见的,它拦截所有其他触摸事件,即使他们不是的MediaController 。

The top half of my app has a VideoView with a MediaController under it. The bottom half is an image with some buttons. While the MediaController is visible, the buttons below are not clickable. It's like while the MediaController is visible, it intercepts all other touch events, even if they are not within the bounds of the MediaController.

周围的任何想法?

推荐答案

您可以检查出我的答案上覆盖 dispatchTouchEvent() 通过的MediaController 点击到底层按钮,但我猜有什么问题您使用的MediaController的方式。您可以发布您的布局?

You can check out my answer on overriding dispatchTouchEvent() to pass clicks through MediaController to an underlying Button, but I'm guessing there's something wrong with the way you use MediaController. Can you post your layout?

UPD: 其实,罢工。我刚一看MediaController code和事实证明,它会创建一个新的窗口本身。这就是为什么你的点击没有得到出动 - 他们派遣到另一个窗口。另外,据我可以告诉从constructor code ,如果​​你通过XML膨胀的MediaController(即使用它的布局文件,然后就发现它按ID从您code) - 它不会产生额外的窗口。这是奇怪的,但我敢肯定,他们有原因是什么。

UPD: Actually, strike that. I've just taken a look at MediaController code and it turns out it creates a new Window for itself. That's why your clicks don't get dispatched — they're dispatched to another window. Also, as far as I can tell from the constructor code, if you inflate the MediaController via xml (i.e. use it in a layout file and then just find it by id from you code) — it won't create the extra Window. That's weird, but I'm sure they had reasons for that.

所以,解决方法是尝试使用的MediaController在布局文件或去 CommonsWare的解决方案。请让我知道如何去的情况下,你给XML的东西一试。

So, the solution is to either try to use MediaController in a layout file or go with CommonsWare's solution. Please, let me know how it goes in case you give the xml thing a try.