我已经使用android.view
包创建了一些图像和电影应用程序。现在我想为Android平板电脑创建相同的功能。
我知道我可以使用Android 3.0的android.animation
软件包,但我找不到任何文档来使用这个软件包应用淡入淡出、缩放效果。我正在尝试转换此包中的所有源代码。
如何使用ValueAnimator
和ObjectAnimator
?在Api演示中,我发现了这段用于衰落的代码。但是如何分配Alpha值?在view.animation
中,我有fromAlpha, toAlpha...
ValueAnimator fadeAnim = ObjectAnimator.ofFloat(newBall, "alpha", 1f, 0f);
fadeAnim.setDuration(250);
fadeAnim.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
balls.remove(((ObjectAnimator)animation).getTarget());
}
});
再次,我有这个代码片段:
ValueAnimator anim = ValueAnimator.ofFloat(0f, 1f);
anim.setDuration(500);
anim.start();
我什么时候使用ValuAnimator
,什么时候使用ObjectAnimator
?
在android开发者博客上有两篇关于这个主题的博客文章,http://android-developers.blogspot.com/2011/02/animation-in-honeycomb.html和http://android-developers.blogspot.com/2011/05/introducing-viewpropertyanimator.html
我强烈推荐这两篇文章,因为我在阅读后对新的动画API有了很好的理解。