与屏幕方向和MediaController DialogFragment问题 [英] DialogFragment issues with screen orientation and MediaController

查看:386
本文介绍了与屏幕方向和MediaController DialogFragment问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,它播放视频的 DialogFragment 。我已经加入的MediaController VideoView 但有两个问题:

  • 的MediaController 背后隐藏的 DialogFragment
  • 更改屏幕方向时 DialogFragment 是一个异常显着的成果,该活动有泄露的窗口
  • I have an app which plays videos in a DialogFragment. I have added MediaController to the VideoView however there are two issues:

  • MediaController is hidden behind the DialogFragment.
  • Change in screen orientation when the DialogFragment is visible results in an exception that the activity has a leaked window
  • 对于第一个,我尝试使用 linearLayoutParent.bringChildToFront(mediaControls)没有工作。我不知道该如何处理第二个。

    For the first one, I tried using linearLayoutParent.bringChildToFront(mediaControls) which did not work. And I do not know how to deal with the second one.

    帮助我。 :)

    推荐答案

    尽管这是一个老问题,我也显示在 VideoView > DialogFragment 并有其中的MediaController 是背后隐藏着同一个问题的 DialogFragment

    Although this is an old question, I was also displaying a VideoView in a DialogFragment and had the same issue where the MediaController was hidden behind the DialogFragment.

    对于任何人,也在寻找做同样的,这就是我所做的。

    For anyone that is also looking at doing the same, this is what I did.

    //Remove the mediaController from it's parent view.
    ((ViewGroup) mediaController.getParent()).removeView(mediaController);
    //Add the mediaController to a FrameLayout within your DialogFragment.
    ((FrameLayout) findViewById(R.id.controlsWrapper)).addView(mediaController);
    

    只要确保你的的FrameLayout 填满屏幕的宽度,并设置重力屏幕的底部。

    Just make sure your FrameLayout fills the width of the screen, and set the gravity to the bottom of the screen.

    另外请注意,敲击 VideoView 将不会显示和隐藏的MediaController (出于某种原因)。

    Also note that tapping the VideoView will not show and hide the MediaController (for some reason).

    所以你需要添加一个 View.onClickListener VideoView 添加和删除的MediaController

    So you'll need to add a View.onClickListener to the VideoView to add and remove the MediaController.

    这篇关于与屏幕方向和MediaController DialogFragment问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆