如何为布局设置两个动画并在方向改变时触发?

How to set two animations to layouts and trigger it when the orientation changes?

我希望我的布局以动画方式旋转 90 度 (left/right),而不是为其横向模式创建新的 xml 布局。

尝试将这段代码添加到您的 onCreate() 方法中。我无法尝试,但这应该可行,因为它在更改方向时也会调用 oncreate 方法。

if(getResources().getConfiguration().orientation==Configuration.ORIENTATION_PORTRAIT){
        //insert your code here when it is portrait
    }
    else if(getResources().getConfiguration().orientation==Configuration.ORIENTATION_LANDSCAPE){
        //insert your code here when it is landscape
    }