从 xml 资源加载后更新/更改 Android 中的动画
从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
? 基本上我有一些云在屏幕上移动。如果用户点击云,我想显示下雨。我不想为不同的雨滴图像提供太多的动画资源,单个动画将满足所有需要更改起点的水滴突出
How can i update attribute of animation in java code after loading from xml?
I have a rain drop fall animation defined in 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" />
after loading this animation
rainDropAnimation =AnimationUtils.loadAnimation(this, R.anim.cloud_fall_down);
how can i change fromYDelta
of animation?
basically i have some cloud moving on screen. i wants to show rain if user tap on a cloud. and i don't want to have to many animation resource for different rain drop image,a single animation will serve all drop juts need to change starting point
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不确定这是否对任何人都有帮助,但我使用
TranslateAnimation
解决了我的问题。这是动画的源代码:
https://github.com/naveed-ahmad/Android-Game-Pack/blob/feature/UI/src/com/nav/gamepack/shared/WelcomeActivity.java#L192
Not sure if this could be helpful for anyone BUT I solve my problem using
TranslateAnimation
.Here is source code of animation:
https://github.com/naveed-ahmad/Android-Game-Pack/blob/feature/UI/src/com/nav/gamepack/shared/WelcomeActivity.java#L192