我正在尝试使用Animator集按顺序播放一组动画。除了alpha动画(set1)之外,其他一切都正常。它从0.25f更改为1,但在整个动画中它并没有褪色,在set1动画结束时,它从0.25更改为1,并且没有考虑setDuration(结果是我没有得到效果中的淡入淡出)。所以我没有淡入淡出效果...当我自己做这个动画时,淡入淡出的效果是there....Any的想法吗?
我正在使用非常棒的nineoldandroids库来实现这一点。
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final ImageView image = (ImageView) findViewById(R.id.image);
final AnimatorSet set = new AnimatorSet();
set.play(ObjectAnimator.ofFloat(image, "translationX", 0, 100).setDuration(3000));
final AnimatorSet set1 = new AnimatorSet();
//THIS IS THE PROBLEMATIC ANIMATION!!
set1.play(ObjectAnimator.ofFloat(image, "alpha", 0.25f, 1).setDuration(3000));
final AnimatorSet set2 = new AnimatorSet();
set2.play(ObjectAnimator.ofFloat(image, "translationX", 100, 200).setDuration(3000));
final AnimatorSet set3 = new AnimatorSet();
set3.playSequentially(set,set1,set2);
set3.start();
} 发布于 2014-02-16 20:58:39
在使用4.0+时
ObjectAnimator alphaAnimation = ObjectAnimator.ofFloat(image, View.ALPHA, 0,1);发布于 2012-12-05 13:46:33
尝尝这个。
ObjectAnimator.ofFloat(image, "alpha", 0.25f, 1, 1)发布于 2014-02-16 21:04:40
您应该在布局完成后启动对象动画。
final View image = findViewById(R.id.image);
final ViewTreeObserver observer = image.getViewTreeObserver();
observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
observer.removeOnGlobalLayoutListener(this);
// start animators
}
});https://stackoverflow.com/questions/11070067
复制相似问题