Naveed
Naveed

Reputation: 11167

update/change animation in Android after loading from xml resource

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

Upvotes: 4

Views: 960

Answers (1)

Naveed
Naveed

Reputation: 11167

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

Upvotes: 1

Related Questions