更改屏幕方向后保留输入动画

时间:2017-07-24 10:39:12

标签: android android-studio animation tablet screen-orientation

我正在开发智能手机和平板电脑支持的应用。对于智能手机,屏幕方向设置为纵向(在清单中),对于平板电脑,方向将以编程方式更改为横向。

问题:如果我以编程方式更改了方向,则活动会输入我之前设置的动画,并且意图消失。如何保持屏幕动画?

我还尝试覆盖onCreate

中的屏幕动画
 @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_test);


    this.phone = getResources().getBoolean(R.bool.portrait_orientation);

    if(phone){
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }else{
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        getWindow().getAttributes().windowAnimations = R.style.Animation_activity_slide_left;

    }
}

活动的清单标签:

android:configChanges="orientation|locale|layoutDirection|screenSize|keyboardHidden"
android:screenOrientation="portrait"

提前致谢!

1 个答案:

答案 0 :(得分:0)

要解决此问题,我从清单中移除了screenOrientation="portrait,我只是以编程方式处理了onCreate