Search code examples
androidxmlanimationandroid-animation

Translate animate an arrow image from left to right and right to left in an infinite loop


I have an image button that is an arrow, and by clicking it, more menu items can be seen. So to hint user, I have to animate it such that it moves (in a specific position boundary which I don't know yet because I am not even close to what I want to see) from right to left and left to right constantly. How can I achieve this by using an anime XML file and calling it in my Java code? Currently I am trying to modify a scaling animation to translating animation but I am not getting anywhere.The arrow is not moving at all. Following is the code for the XML file.

<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="100"
    android:fromXDelta="0.5"
    android:fromYDelta="0.5"
    android:toXDelta="1.0"
    android:toYDelta="1.0"
    android:repeatCount="infinite"
    android:fillAfter="true"
    android:repeatMode="reverse"
    android:pivotX="50%"
    android:pivotY="50%" />

The Java code is:

animation = AnimationUtils.loadAnimation(getApplicationContext(),
                R.anim.zoomin);
        a1.setAnimation(animation);
        a2.setAnimation(animation);

Solution

  • My apologies for posting this but this seems to work fine as wine. Just the values of scaling and the duration was so small that the animation seemed negligible. The translating animation on an object will work like this. If anyone is in search of animating an object like this, this is it. Please note that a1 and a2 are the imageviews here.