Rearrangement of the layout for playing video in full screen mode when the screen is rotated

In action, I embedded the Video widget (VideoView or MediaPlayer associated with SurfaceView), the size of which must be adapted when the screen is rotated. This activity is used as content in TabHost.

My current approach

To handle the rotation of the screen, I provided two layouts for portrait and the other for landscape orientation (placed in the folders. / Res / layout and. / Res / layout-land).

The problem with this approach is that a new action is created for each rotation, so I don’t use the same MediaPlayer (or VideoView) => I start the video from the very beginning every time I rotate the screen. Since video is transmitted from the Internet, there is no way to save a position in a video in order to search for that position when restarting the video in another operation.

What i would like to do

I need to be able to translate / scale / hide views inside an Activity when the screen rotates. Translation / scaling should support the layout in order to have a layout adapted to different screen sizes.

Desired animation / layout

My questions

  • How to translate / move views to the upper left position of the screen?
  • How to hide / translate View off-screen to fade view?
  • How to scale / resize View to adjust its size to free space around it?

  • What interface, callback do I need to implement in order to be notified of the rotation of the screen to start these transformations?

+8
android layout rotation video fullscreen
source share
1 answer

I finally found a good way to do this. The Android documentation states that when you need to process modifications (orientation, keyboard ...) without re-creating a new action, you must do this by overriding the onConfigurationChanged method of the Activity class. You must indicate the changes that you make sense in the manifest file of your activity.

You can find more information about this here .

In my case, the Activity manifest looks like this:

<activity android:name=".MyActivity" android:configChanges="orientation"></activity> 

And inside my MyActivity activity, I added the following method:

 @Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); int visibility = View.VISIBLE; if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) { visibility = View.GONE; } getTabHost().getTabWidget().setVisibility(visibility); } 

with the following location of my activity:

 <?xml version="1.0" encoding="utf-8"?> <TabHost xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/tabhost" android:layout_width="fill_parent" android:layout_height="fill_parent"> <LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TabWidget android:id="@android:id/tabs" android:layout_width="fill_parent" android:layout_height="wrap_content" /> <FrameLayout android:id="@android:id/tabcontent" android:layout_width="fill_parent" android:layout_height="fill_parent" /> </LinearLayout> </TabHost> 

Thus, when I hide / show the tabWidget panel, the VideoView (which is added to the contents of the TabHost changes in size, and when in the landscape, I have a full-screen movie view.

I hope this helps some of you.

+9
source share

All Articles