Disable orientation animations when launching activity
I have set my app's orientation to sensor and I am having the app handle all the orientation changes. Everything is working as expected while the app is running.
The problem occurs during the initial launch of the app. If the phone is in portrait mode and a user starts my app, I see my app background appear, then it will do an orientation rotation to landscape view, because I use setRequestedOrientation() within my app. I want the orientation change but I don't want the rotation animation that comes with it. I just want a hard switch between portrait and landscape.
I have tried using overridePendingTransition(0,0) in onCreate, surfaceChanged, or in onConfigurationChanged with no luck. Is there somewhere else I should put this? I believe that using (0,0) should disable the pendin开发者_JAVA百科g animation.
I get the desired effect if I set System Settings->Display->Animations to none. I have tried to set styles for my activity and that did not work either.
If the problem is only at application startup time, you can do this to force the landscape orientation with no animation:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapp"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon"
android:label="@string/app_name">
<activity android:name="com.example.myapp.MyActivity"
android:screenOrientation="landscape">
...
</activity>
</application>
</manifest>
And then you can programmatically change the android:screenOrientation
setting later in the code to allow landscape and portatit if you would like to.
精彩评论