开发者

Tablet Android Orientation when launch Activity

开发者 https://www.devze.com 2023-04-12 17:49 出处:网络
I have a strange problem on orientation handling on Samsung Tablets. Basically, I have this app that it is supposed to run only in Landscape if running on tablet and portrait if i\'m on a phone.

I have a strange problem on orientation handling on Samsung Tablets. Basically, I have this app that it is supposed to run only in Landscape if running on tablet and portrait if i'm on a phone. To do that I check on wich device I'm, and then I use the onConfigurationChanged callback to set the right layout. It works perfectly on the phone. But on tablet, if I'm holding it in portrait position, when launch another activity within the same app I see a flash oh the home screen (that's not cool), so the orientation (and also the android bar) goes in portrait position, the second activity is loaded in portrait (that's wrong) and just after a while the second activity ch开发者_开发技巧ange orientation to the right landscape position. There is a way to simple load the second activity directly in landscape? Thanks

Francesco


Since you are using the same activity just test for the android version and set the orientation programatically. Like this:

  if(Build.VERSION.SDK_INT >= 11){
           //If build is tablet honeycomb or greater sdk such as 12, or 13
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);


    }
    else{
        //If device SDK is lower than 11 the view is set to PORTRAIT
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }

You could also do

Build.VERSION_CODES.HONEYCOMB

To test for tablet. This would be more specific to honeycomb. You also do HONEYCOMB_MR1 & MR2.


If you want to load any activity directly in landscape then mention screenOrientation directly in a particular activity inside the AndroidManifest.xml file:

android:screenOrientation="landscape"

this will load your activity directly in landscape orientation.

0

精彩评论

暂无评论...
验证码 换一张
取 消