android - 从 xml 资源加载后更新/更改 Android 中的动画

标签 android animation android-animation android-resources

如何在从 xml 加载后更新 java 代码中的动画属性?

我有一个在 xml 中定义的雨滴落下动画。

<?xml version="1.0" encoding="utf-8"?>

<set xmlns:android="http://schemas.android.com/apk/res/android"  
    android:shareInterpolator="false">
  <translate android:fromYDelta="10%p" 
    android:toYDelta="70%p"
    android:duration="2000" 
    android:repeatCount="1"
    />
   <scale
    android:interpolator="@android:anim/accelerate_decelerate_interpolator"
    android:fromXScale="1.2"
    android:toXScale=".5"
    android:fromYScale="1.2"
    android:toYScale="0.5"
    android:pivotX="50%"
    android:pivotY="50%"
    android:fillAfter="false"
    android:duration="2000" />

加载此动画后

 rainDropAnimation =AnimationUtils.loadAnimation(this, R.anim.cloud_fall_down);

如何更改动画的 fromYDelta? 基本上我有一些云在屏幕上移动。如果用户点击云,我想显示下雨。而且我不想为不同的雨滴图像提供太多动画资源,单个动画将服务于所有需要更改起点的雨滴突出部分

最佳答案

不确定这是否对任何人有帮助,但我使用 TranslateAnimation 解决了我的问题。

动画源代码如下: https://github.com/naveed-ahmad/Android-Game-Pack/blob/feature/UI/src/com/nav/gamepack/shared/WelcomeActivity.java#L192

关于android - 从 xml 资源加载后更新/更改 Android 中的动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9282918/

相关文章:

Android Studio 和 AndEngine - 包不存在

ios - 删除按钮 ios swift 的所有动画

android - 更改和删除的动画不适用于 RecyclerView

jquery - 如何检测正在运行的异步 AJAX 调用并将另一个调用放入 jQuery 队列中?

android - TextView 轻微移动

javascript - 控制 Sprite 动画速度

objective-c - 使用 block 的多级动画

android - Content Transition NONE 带有空的共享元素

android - 布局转换 : Animate View next to an expanding View

Android FFmpeg 即时转换