1

I got a question about Android display activity in horizontal direction, Here is my code in AndroidMainfest.xml:

 <activity
        android:name="com.runmaf.paodong.activity_new.ResultChartDataActivity"
        android:configChanges="keyboardHidden|orientation|screenSize"
        android:screenOrientation="landscape">
 </activity>

and in most cases the activity display in horizontal direction: enter image description here

but sometimes the activity display in the vertical direction like here: enter image description here

And I also try to add the code under here into Activity's onCreate method, but it will display in vertical direction somtimes: setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

And I also close the phone's Automatic rotation function! I don't know what is it happen? need you help!

Botasky
  • 35
  • 8

1 Answers1

0

for a general answer (since you have given less code)

you can set any of below to, android:screenOrientation inside activity tag

android:screenOrientation=["unspecified" | "behind" |
                                     "landscape" | "portrait" |
                                     "reverseLandscape" | "reversePortrait" |
                                     "sensorLandscape" | "sensorPortrait" |
                                     "userLandscape" | "userPortrait" |
                                     "sensor" | "fullSensor" | "nosensor" |
                                     "user" | "fullUser" | "locked"]

and this specifies The orientation of the activity's display on the device. but

Note : The system ignores this attribute if the activity is running in multi-window mode. https://developer.android.com/guide/topics/ui/multi-window.html

if its not the case in your's dig into the code and see where the places that rotation attributes has been used eg: view.setRotaion(90);

also

Don't apply the orientation to the application element, instead you should apply the attribute to the activity element, and you must also set configChanges as noted below

<activity
   android:screenOrientation="portrait"
   android:configChanges="orientation|keyboardHidden">
</activity>

Note : android:configChanges "configChanges means that the configuration change is handled by the activity itself. Without it, the activity will be restarted if there is an orientation change" "

if you've specified that the orientation is "portrait" how would it ever change? It can change if you launch another activity that alters the orientation, then that new activity exits, returning you back to your activity. For example, the default image capture intent on the Samsung Galaxy S3 does that in certain orientations"

quoting from this https://stackoverflow.com/a/4885663/5188159

Community
  • 1
  • 1
Charuක
  • 12,953
  • 5
  • 50
  • 88
  • thanks for your answer, but I really do like what you say, it's not work, and my application doesn't running with multi-window mode. – Botasky Dec 06 '16 at 03:03