Skip to content Skip to sidebar Skip to footer

Android Animation Xml Issues

I'm trying to use Android's animation framework to have my ImageView move in a diamond pattern. Here's my animation.xml: Copy

Solution 2:

Try this:

Animationanim= AnimationUtils.loadAnimation(getApplicationContext(), R.anim.diamond);
findViewById(R.id.img).setAnimation(anim);
anim.start();

You should also probably change the animations to load one after the other. I think that set you have created will try to play all the animations at once, and that won't work very well.

Use an animationListener like this:

anim.setAnimationListener(newAnimation.AnimationListener() {

        publicvoidonAnimationStart(Animation animation) {
        }

        publicvoidonAnimationEnd(Animation animation) {
            Animation anim = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.diamond2);
            findViewById(R.id.img).setAnimation(anim);
            anim.start();
        }

        publicvoidonAnimationRepeat(Animation animation) {
        }
    });

Solution 3:

Use this one it works, i hve tested it

<set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="true">
    <translate 
        android:fromXDelta="40%p" android:toXDelta="90%p" 
        android:fromYDelta="10%p" android:toYDelta="40%p" 
        android:duration="500" android:startOffset="0"
        />
    <translate 
        android:fromXDelta="0%p" android:toXDelta="-40%p" 
        android:fromYDelta="0%p" android:toYDelta="40%p" 
        android:duration="500" android:startOffset="500"/>
    <translate 
        android:fromXDelta="0%p" android:toXDelta="-40%p" 
        android:fromYDelta="0%p" android:toYDelta="-40%p" 
        android:duration="500" android:startOffset="1000"/>
    <translate 
        android:fromXDelta="0%p" android:toXDelta="40%p" 
        android:fromYDelta="0%p" android:toYDelta="-40%p" 
        android:duration="500" android:startOffset="1500"/>
    </set>

Solution 4:

Use this animation xml code. It works:

<setxmlns:android="http://schemas.android.com/apk/res/android"android:shareInterpolator="true"><translateandroid:fromXDelta="40%"android:toXDelta="90%"android:fromYDelta="10%"android:toYDelta="40%"android:duration="500"android:startOffset="0"/><translateandroid:fromXDelta="90%"android:toXDelta="40%"android:fromYDelta="40%"android:toYDelta="90%"android:duration="500"android:startOffset="500"/><translateandroid:fromXDelta="40%"android:toXDelta="10%"android:fromYDelta="90%"android:toYDelta="40%"android:duration="500"android:startOffset="1000"/><translateandroid:fromXDelta="10%"android:toXDelta="40%"android:fromYDelta="40%"android:toYDelta="10%"android:duration="500"android:startOffset="1500"/></set>

Post a Comment for "Android Animation Xml Issues"