Dialogfragment Issues With Screen Orientation And Mediacontroller
Solution 1:
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);
Just make sure your FrameLayout
fills the width of the screen, and set the gravity to the bottom of the screen.
Also note that tapping the VideoView
will not show and hide the MediaController
(for some reason).
So you'll need to add a View.onClickListener
to the VideoView
to add and remove the MediaController
.
Solution 2:
To your second point:
Try setRetainInstance(true)
in your onCreate of the Fragment. With this the Fragment will survive while the Activity gets destroyed, like on a configuration change. If you are using the support library you will need this to really prevent the closing of your Fragment:
@OverridepublicvoidonDestroyView() {
if (getDialog() != null && getRetainInstance())
getDialog().setDismissMessage(null);
super.onDestroyView();
}
This is needed to overwrite the dismiss listener of the DialogFragment.
If you have calls on the Activity from the Fragment update the context / callback accordingly to keep track of the reference to the new created Activity. Therefor you can use onAttach() or onActivityCreated().
Post a Comment for "Dialogfragment Issues With Screen Orientation And Mediacontroller"