简体   繁体   中英

How to simply animate views in android

I've been looking around the web and also on the developer guide for Android but couldn't find any SIMPLE way to animate my views sequentially as I want. I'd like to be able to execute several animations like this

yourView.animate().xBy(100).setDuration(500);
yourView.animate().alpha(0).setDuration(500);
yourView.animate().whateverIwannaDo(...).setDuration(...);
...

with (or without) a waiting time between each animation and without having to use AnimatorSet or AnimationSet (which I don't understand even after reading the developer guide) :/

If there is no way to do so then would there be any clear guide which would explain step by step how to use AnimatorSet and all that.

I hope you guys will be indulgent in relation to my problem.

Thanks in advance.

I encourage you to use NineOldAndroid . It's a library that allow to use Honeycomb animation API for all versions of the Android platform.

AnimatorSet set = new AnimatorSet();
    set.playTogether(
        ObjectAnimator.ofFloat(myView, "rotationX", 0, 360),
        ObjectAnimator.ofFloat(myView, "translationX", 0, 90),
        ObjectAnimator.ofFloat(myView, "scaleX", 1, 1.5f),
        ObjectAnimator.ofFloat(myView, "alpha", 1, 0.25f, 1));
set.setDuration(5 * 1000).start();

To use this library you have three options:

With gradle , in your build.gradle configuration file:

buildscript {
    repositories {
        mavenCentral()
    }

    dependencies {
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.2+'
    }
}

dependencies {
    compile 'com.nineoldandroids:library:2.4.0'
}

Using maven :

<dependency>
  <groupId>com.nineoldandroids</groupId>
  <artifactId>library</artifactId>
  <version>2.4.0</version>
</dependency>

Also, you can add it to your project as a dependency jar

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM