Question

I have an app that would play a video. When in portrait mode, the video takes up 1/3 of the screen and I change it to fullscreen when changed to landscape. This works fine in a handheld phone layout. I use setLayoutParams to change the layout of the videoview container to fullscreen on the onConfigurationChanged handler. I did this instead of declaring another layout because I don't want the videoview to rebuffer when changing orientation.

But I have another layout for tablets which utilizes 2 Fragments. The video plays in the bottom fragment. When I change the orientation, how can I set the layoutparams to occupy the entire screen and cover the other fragment as well. It will be great if there will be an approach that would work on both the handheld and tablet layouts since this functionality is handled by the detailsFragment class which is shared by both.

UPDATE: Here's the concised version of my layout.
main_activity.xml

<LinearLayout>
   <FrameLayout id="listFragment" weight=1/>
   <FrameLayout id="detailFragment" weight=2/>
</LinearLayout>

detailFragment.xml

<RelativeLayout>
   <TextView/>
   <RelativeLayout>
      <VideoView>
   <RelativeLayout>
   <Button/>
</RelativeLayout>

When the onConfigurationChanged is called, I create a RelativeLayout.LayoutParams and set it to the videoview using videoview.setLayoutParams(lp);. Which means this resizes the parent of the videoview. When I temporarily detach the listfragment, the detailFragment still occupies the same height and I still have a space for the listFragment. I think this is because the FrameLayout for the listFragment is still there and occupying 1/3 of the screen. How can I get the detailFragment to occupy the entire screen when the listFragment is detached from the view.

Was it helpful?

Solution

Again you can handle this in the onConfigurationChanged() callback of the Activity; detach the other Fragment when it is in portrait mode, and reattach it when it's in landscape mode.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top