Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ObjectAnimator not fading in

I am trying to play a set of animations sequentially using the Animator set. Everything is working except for the alpha animation(set1). It is changing from 0.25f to 1 but it is not fading throughout the animation and at the end of the set1 animation it is changing from 0.25 to 1 and not taking in consideration the setDuration(as a result I am not getting the fade in effect). So I don't have the fade in effect... When I do this animation by itself the fade in effect is there....Any ideas?

I am using the wonderful nineoldandroids library to implement this.

@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(); }    
like image 898
user182192 Avatar asked Jun 17 '12 08:06

user182192


People also ask

What is ObjectAnimator?

android.animation.ObjectAnimator. This subclass of ValueAnimator provides support for animating properties on target objects. The constructors of this class take parameters to define the target object that will be animated as well as the name of the property that will be animated.

What is object Animator in Android?

ObjectAnimator is a Subclass of ValueAnimator, which allows us to set a target object and object property to animate. It is an easy way to change the properties of a view with a specified duration. We can provide the end position and duration of the animation.


2 Answers

While working on 4.0+

ObjectAnimator alphaAnimation = ObjectAnimator.ofFloat(image, View.ALPHA, 0,1); 
like image 173
Zen Avatar answered Sep 19 '22 05:09

Zen


try this.

ObjectAnimator.ofFloat(image, "alpha", 0.25f, 1, 1) 
like image 31
Mohsin Shafqat Avatar answered Sep 20 '22 05:09

Mohsin Shafqat