属性动画注意点
- ofFloat等参数注意点
ObjectAnimator xiaoAniator = ObjectAnimator.ofFloat(llXiao, "translationX", 400f);
equals to
ObjectAnimator xiaoAniator = ObjectAnimator.ofFloat(llXiao, "translationX", 0,400f);
- Animator的start方法,应该在Animator的addListener之后调用
//
ObjectAnimator xiaoAniator = ObjectAnimator.ofFloat(llXiao, "translationX", 400f,0);
xiaoAniator.setInterpolator(new AccelerateDecelerateInterpolator());
xiaoAniator.setDuration(500);
// 公共的 PropertyValuesHolder
PropertyValuesHolder holder_scaleX = PropertyValuesHolder.ofFloat("scaleX", 10f, 1f);
PropertyValuesHolder holder_scaleY = PropertyValuesHolder.ofFloat("scaleY", 10f, 1f);
PropertyValuesHolder holder_alpha = PropertyValuesHolder.ofFloat("alpha", 0.5f, 1f);
// yellow point ,400ms
PropertyValuesHolder yellowHolder_translateX = PropertyValuesHolder.ofFloat("translationX", 2000f,0);
PropertyValuesHolder yellowHolder_translateY = PropertyValuesHolder.ofFloat("translationY", -3000f,0);
final ObjectAnimator yellowAnimator = ObjectAnimator.ofPropertyValuesHolder(ivYellowView, holder_scaleX,
holder_scaleY, yellowHolder_translateX, yellowHolder_translateY, holder_alpha);
yellowAnimator.setDuration(400);
// green point, 400ms
PropertyValuesHolder greenHolder_translateX = PropertyValuesHolder.ofFloat("translationX", 1000f,0);
PropertyValuesHolder greenHolder_translateY = PropertyValuesHolder.ofFloat("translationY", 1500f,0);
final ObjectAnimator greenAnimator = ObjectAnimator.ofPropertyValuesHolder(ivGreenView, holder_scaleX,
holder_scaleY, greenHolder_translateX, greenHolder_translateY, holder_alpha);
greenAnimator.setStartDelay(100);
greenAnimator.setDuration(400);
// blue point,400ms
PropertyValuesHolder blueHolder_translateX = PropertyValuesHolder.ofFloat("translationX", -2000f,0);
PropertyValuesHolder blueHolder_translateY = PropertyValuesHolder.ofFloat("translationY", -2000f,0);
final ObjectAnimator blueAnimator = ObjectAnimator.ofPropertyValuesHolder(ivBlueView, holder_scaleX,
holder_scaleY, blueHolder_translateX, blueHolder_translateY, holder_alpha);
blueAnimator.setStartDelay(200);
blueAnimator.setDuration(400);
// Slogan,400ms
PropertyValuesHolder sloganHolder_scaleX = PropertyValuesHolder.ofFloat("scaleX", 5f, 1f);
PropertyValuesHolder sloganHolder_scaleY = PropertyValuesHolder.ofFloat("scaleY", 5f, 1f);
PropertyValuesHolder sloganHolder_translateX = PropertyValuesHolder.ofInt("translationX", -2000);
final ObjectAnimator sloganAnimator = ObjectAnimator.ofPropertyValuesHolder(ivSlogan, sloganHolder_scaleX,
sloganHolder_scaleY, sloganHolder_translateX);
sloganAnimator.setDuration(400);
/**
* startAnimator
*/
xiaoAniator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationStart(Animator animation) {
llXiao.setVisibility(View.VISIBLE);
}
@Override
public void onAnimationEnd(Animator animation) {
greenAnimator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
ivSlogan.setVisibility(View.VISIBLE);
sloganAnimator.start();
}
});
sloganAnimator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
runJob(new VersionCheckJob(PackageUtils.getVersionName(context)));
}
}, 300);
notAnimation = false;
}
});
yellowAnimator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationStart(Animator animation) {
ivYellowView.setVisibility(View.VISIBLE);
}
});
blueAnimator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationStart(Animator animation) {
ivBlueView.setVisibility(View.VISIBLE);
}
});
greenAnimator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationStart(Animator animation) {
ivGreenView.setVisibility(View.VISIBLE);
}
});
yellowAnimator.start();
greenAnimator.start();
blueAnimator.start();
}
});
xiaoAniator.start();
想要进一步了解属性动画请戳:
属性动画进阶