make a fullScreen in only layout-land android when play videoView

android, android-layout, android-manifest, android-videoview

Solution

You should add your videoview (or content Parent) as last element in your layout file. and use the next code:

private RelativeLayout.LayoutParams paramsNotFullscreen; //if you're using RelativeLatout           

@Override
public void onConfigurationChanged(Configuration newConfig) 
{
    super.onConfigurationChanged(newConfig);


    if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) //To fullscreen
    {
        paramsNotFullscreen=(RelativeLayout.LayoutParams)mVideoView.getLayoutParams();
        RelativeLayout.LayoutParams params=new LayoutParams(paramsNotFullscreen);
        params.setMargins(0, 0, 0, 0);
        params.height=ViewGroup.LayoutParams.MATCH_PARENT;
        params.width=ViewGroup.LayoutParams.MATCH_PARENT;
        params.addRule(RelativeLayout.CENTER_IN_PARENT);
        mVideoView.setLayoutParams(params);

    } 
    else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) 
    {
        mVideoView.setLayoutParams(paramsNotFullscreen);
    }
}

It gets a copy of videoview layoutparams and saves it in a global variable. then creates a new layoutparams object with the previous values but setting now the limits to match_parent and sets it in your videoview. You videoview now is in fullscreen. When you put your device in portrait, paramsNotFullscreen restores previous values.

UPDATE:

In your manifest file you must add into Activity declaration the following code to avoid the activity restart:

android:configChanges="screenLayout|screenSize|orientation"

Problem

I'm creating android app to play liveStream, I added the videoView in my layout.xml and added the folder of layout-land I want to make the app shows video full screen in only layout-land not portrait so I added the following code in onCreate(): ``` public void onConfigurationChanged(Configuration newConfig){ if(getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE { getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); } else if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { getWindow().setFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); } } ``` but my problem is when I rotate the device it restarts the activity and this lead the stream of video to stop and I want to prevent this. So. I added to manifest this line ``` android:configChanges="keyboard|keyboardHidden|orientation|screenSize" ``` but this leads the code of onCreate() to be executed once only. How to make my app plays the video stream continuously and when I rotate device to make full screen in layout land then when back to portrait make it normal? Hope that anyone got my mean. Thanks in advance.

Original source