athulya k
athulya k

Reputation: 145

How can I control the animation speed in android

I have a music app and the music notations perform an animation from right to left, I want to control the animation speed, while they are performing.Can anyone please help me for that?

My animation layout is:

<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate
    android:fromXDelta="500%" android:toXDelta="0%"
       android:fromYDelta="0%" android:toYDelta="0%"
       android:duration="10000" 
        android:fillAfter="true"
        android:repeatCount="infinite"/>

And my code to perform the animation is:

Animation am=AnimationUtils.loadAnimation(this, R.anim.note);
        music1.startAnimation(am);

Upvotes: 3

Views: 6638

Answers (4)

Mark Ezberg
Mark Ezberg

Reputation: 665

From official documentation:

ValueAnimator animation = ValueAnimator.ofFloat(0f, 100f);
animation.setDuration(1000);
animation.start()

In your case:

music.setDuration(setValue);

Upvotes: 0

Pankaj Arora
Pankaj Arora

Reputation: 10274

change in the duration will control the speed of animation in your file.

  android:duration="10000" // here you have to change the time in milliseconds.

Upvotes: 1

AndroidManifester
AndroidManifester

Reputation: 291

you can implement onTouchListener to control your animation speed at the run time. inside touch listener event put coding to change your animation duration.

Upvotes: 0

Shivansh Saxena
Shivansh Saxena

Reputation: 196

set your android:duration with this help you can control your animation speed

android:duration="300"

Upvotes: 4

Related Questions