Md. Zakir Hossain
Md. Zakir Hossain

Reputation: 1092

How to achieve Left to Right animation in Android

I want to Left to Right Arrow Animation in my application like below Image: enter image description here

I've tried below Code:

    ImageView arrowImage = sbView.findViewById(R.id.arrowID);
    ScaleAnimation scale = new ScaleAnimation(0.5f, 0.5f, 1, 1, ScaleAnimation.RELATIVE_TO_SELF, .5f,
            ScaleAnimation.RELATIVE_TO_SELF, .5f);
    scale.setDuration(700);
    scale.setRepeatCount(INFINITE);
    scale.setRepeatMode(REVERSE);
    scale.setFillAfter(true);
    scale.setInterpolator(new OvershootInterpolator());
    arrowImage.startAnimation(scale);

But my code does't work as my expectation. I tried different solution from internet but failed to achieve result.

Upvotes: 0

Views: 443

Answers (2)

Ashvin solanki
Ashvin solanki

Reputation: 4809

Animation XML file

<set
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/linear_interpolator"
    android:fillAfter="true">

   <translate
        android:fromXDelta="-10%p"
        android:toXDelta="10%p"
        android:duration="1200" />
</set>

To load this animation

viewObject.startAnimation(AnimationUtils.loadAnimation(activity, R.anim.filename));

For handle movement position use xml attributes fromXDelta and toXDelta change Values

  • android:fromXDelta

Float or percentage. Starting X offset. Expressed either: in pixels relative to the normal position (such as "5"), in percentage relative to the element width (such as "5%"), or in percentage relative to the parent width (such as "5%p").

  • android:toXDelta

Float or percentage. Ending X offset. Expressed either: in pixels relative to the normal position (such as "5"), in percentage relative to the element width (such as "5%"), or in percentage relative to the parent width (such as "5%p").

For More Helpful Information visit Animation-Resource

Upvotes: 1

Ahmed.ess
Ahmed.ess

Reputation: 265

this is translation, try TranslateAnimation

TranslateAnimation(float fromXDelta, float toXDelta, float fromYDelta, float toYDelta)

Upvotes: 1

Related Questions