android - 以编程方式翻译 Activity 的动画

标签 android android-activity android-animation

这似乎是一项简单的任务,但我找不到解决方案。

我需要使用自定义动画从 [Activity A] 切换到 [Activity B]。 为此,我将 [Activity B](在 onCreate 中)设置为:

overridePendingTransition(R.animator.slide_in, R.animator.slide_out);

R.animator.slide_in[Activity B] 中使用代码移动

<translate
        xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="@android:integer/config_mediumAnimTime"
    android:interpolator="@android:anim/decelerate_interpolator"
    android:fromYDelta="100%p"
    android:toYDelta="0%p">
</translate>

R.animator.slide_out是移出[Activity A]的反向动画。

一切正常,但是我想以编程方式设置 R.animator.slide_inandroid:fromYDelta 因为它会不时更改.

有什么技巧?也许我需要以编程方式创建整个动画,但我真的找不到方法......

谢谢!

最佳答案

BUT i wanna set programmatically the android:fromYDelta of R.animator.slide_in cause it can change time to time.

无法以编程方式更改 xml 的动画,您也不能在需要 xml 中的资源以用作动画的 Activity 的 overridePendingTransition 方法中使用对象。

解决方法:

它要么为每个 YDelta 创建多个 xml,这将需要大量 xml 文件,要么只为所有动画坚持使用一个 xml 文件。

关于android - 以编程方式翻译 Activity 的动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25277153/

相关文章:

android - 如何使用 Jetpack Compose 动画创建定时 Instagram 故事加载栏?

安卓手电筒

android - Intent bundle 变量未在 Activity 之间传递

android - 旋转动画后保存图像时如何避免闪烁图像?

android - 单击通知时检查 Activity 是否在屏幕上?(使用 Intent)

android - 如果 android 应用程序不存在,则从 onReceive 方法启动它

android - 如何在 Android 中创建带动画的基于路径的 Logo ?

android - 我收到错误 "cannot find symbol variable fragment"

android - Android 7.1.1 中的 KeyPairGenerator.generateKeyPair()

android - 适用于 Android 的 Google API 缺少 Games.getGamesAuthToken