【发布时间】:2018-10-06 23:33:56
【问题描述】:
我正在尝试为我的应用程序中的活动之间的过渡设置动画。我有 right_to_left.xml 正在处理 Portrait 屏幕方向。
这里是 right_to_left.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="@android:integer/config_shortAnimTime"
android:fromXDelta="100%"
android:interpolator="@android:anim/linear_interpolator"
android:toXDelta="0" />
</set>
这里是 right_to_left_slide_out.xml(在过渡时滑出之前的活动。)
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="@android:integer/config_shortAnimTime"
android:fromXDelta="0"
android:interpolator="@android:anim/linear_interpolator"
android:toXDelta="-100%p" />
</set>
我是在startActivity()之后使用的,Portrait模式没有问题。
但我添加了将屏幕方向更改为横向模式的选项。
如果启用横向模式,我在 onCreate() 中使用以下代码设置请求的方向。
//SCREEN ORIENTATION
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
这很好,活动是在横向模式下创建的,没有任何问题。 但是,当我尝试使用在纵向模式下工作的 overridePendingTransition(R.anim.right_to_left, R.anim.right_to_left_slide_out) 开始活动时,横向模式下似乎没有过渡动画。
有什么我错过的吗?
编辑: 我试图创建一个与 YDelta 一起使用的新动画 xml 文件。它也没有工作。
【问题讨论】:
-
在清单中为您的活动添加
android:configChanges="orientation"
标签: android screen-orientation android-transitions overridependingtransition