Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android : inflated view with a different orientation than the activity

The orientation of my activity is fixed to be landscape. I am inflating 3 different layouts in this activity over an GLsurface view Only one of this will be visible at a time depending on user actions. One of this layout is a video view. I would like to support both vertical and horizontal playing of video. But for all other views it need to be fixed to landscape. How can i achieve this .

Thanks for your time and help

like image 773
png Avatar asked Nov 29 '25 03:11

png


1 Answers

In you AndroidManifest.xml activity declaration remove

android:orientation

tag & add

android:configChanges="keyboardHidden|orientation"

Now override below function in your activity

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);    //To change body of overridden methods use File | Settings | File Templates.
    if (!isVideoViewSet)//change orientation to portrait other Views, skip for Video View
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}

Here using some flag(isVideoViewSet in above code snippet) you can check which view is set and Set activity orientation accordingly.

like image 75
Akhil Avatar answered Nov 30 '25 17:11

Akhil



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!