Fix Screen orientation

[亡魂溺海] 提交于 2019-12-23 21:19:48

问题


I wanted to fix screen orientation as a landscape mode in tab i.e on 7" I am calculating the inch of the device in my coding and is setting it as:

int inch=((int)height_pixel1/(int)xdpi);
if(inch>=6){
    orientation=true;
    this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
} else {
    orientation=false;
    this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}

and the problem is firstly it displays me the screen orientation as according to my requirement,but when processing is going on in between , then it changes the orientation as portrait way and again in landscape way.. It is still toggle between these two orientation and I want to make a fixed orienattion for my whole application...Is there any property that I am missing here??


回答1:


Create a folder layout-xlarge-land and put your XML in it... it should be designed for landsacpe screen.. also You have to give

android:largeScreens="true"  in manifest... 


res/layout/my_layout.xml             // layout for normal screen size ("default")
res/layout-small/my_layout.xml       // layout for small screen size
res/layout-large/my_layout.xml       // layout for large screen size
res/layout-xlarge/my_layout.xml      // layout for extra large screen size
res/layout-xlarge-land/my_layout.xml // layout for extra large in landscape orientation





 <supports-screens android:resizeable=["true"| "false"]
                      android:smallScreens=["true" | "false"]
                      android:normalScreens=["true" | "false"]
                      android:largeScreens=["true" | "false"]
                      android:xlargeScreens=["true" | "false"]
                      android:anyDensity=["true" | "false"]
                      android:requiresSmallestWidthDp="integer"
                      android:compatibleWidthLimitDp="integer"
                      android:largestWidthLimitDp="integer"/>

Refer http://developer.android.com/guide/topics/resources/providing-resources.html




回答2:


Try it out, just set it inside the AndroidManifest.xml file:

<activity android:name=".ActivityName"
              android:label="@string/app_name"
              android:configChanges="orientation|keyboardHidden">  
              // Prevent application restart on orientation change



回答3:


please have a look at this .........

supports-screens android:resizeable=["true"| "false"]
              android:smallScreens=["true" | "false"]
              android:normalScreens=["true" | "false"]
              android:largeScreens=["true" | "false"]
              android:xlargeScreens=["true" | "false"]
              android:anyDensity=["true" | "false"]
              android:requiresSmallestWidthDp="integer"
              android:compatibleWidthLimitDp="integer"
              android:largestWidthLimitDp="integer

............... It will be Handle your screen



来源:https://stackoverflow.com/questions/8209349/fix-screen-orientation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!