i have a transition animation xml
<set
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/linear_interpolator"
    android:fillAfter="true">
    <translate
        android:fromXDelta="100%p"
        android:toXDelta="0%p"
        android:duration="400"/>
</set>
I want to apply this animation on several items but with varying duration. I'm trying to dynamically change duration by calling setDuration and then calling startAnimation.
mSlideLeft.setDuration(400);
view1.startAnimation(mSlideLeft);
mSlideLeft.setDuration(500);
view2.startAnimation(mSlideLeft);
mSlideLeft.setDuration(600);
view3.startAnimation(mSlideLeft);
but all view animation in same duration. How do I dynamically change duration of animation?
You're using the same Animation object for all three Views. So you're calling setDuration on the same object 3 times.
You need to create three separate Animation objects if you want to use three different durations.
Animation firstSlideLeft = AnimationUtils.loadAnimation(context, R.anim.slide_left);
firstSlideLeft.setDuration(400);
view1.startAnimation(firstSlideLeft);
Animation secondSlideLeft = AnimationUtils.loadAnimation(context, R.anim.slide_left);
secondSlideLeft.setDuration(500);
view2.startAnimation(secondSlideLeft);
Animation thirdSlideLeft = AnimationUtils.loadAnimation(context, R.anim.slide_left);
thirdSlideLeft.setDuration(600);
view3.startAnimation(thirdSlideLeft);
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With