I am new in Android. I created ripple animation to hide view, but view do not gone.
Animator anim = ViewAnimationUtils.createCircularReveal(view, 150, 150, 200f, 0f);
anim.start();
I expect that view gone after animation is end.
First of all, the right name for this animation is circular reveal.
You should add the listener to your animation and override method named as onAnimationEnd, then start an animation.
In the onAnimationEnd you should set visibility to the view.
Animator anim = ViewAnimationUtils.createCircularReveal(view, 150, 150, 200f, 0f);
anim.addListener(new AnimatorListenerAdapter() {
#Override
public void onAnimationEnd(Animator animation) {
view.setVisibility(View.INVISIBLE);
}
});
anim.start();
You need to set the duration of the animation
Animator.setDuration(1000)
for example for 1000ms
You need to use setAnimationListener .
Follow this method:
Animator anim = ViewAnimationUtils.createCircularReveal(view, 150, 150, 200f, 0f);
anim.setDuration(1000);
anim.start();
anima.setAnimationListener(new AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
#Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
#Override
public void onAnimationEnd(Animation animation) {
animation.cancel();
//hide
}
});
Related
I am animating a view to move off the screen, on complete i would like to call another function but I cant seem to find a onComplete method.
int originalPos[] = new int[2];
icons.getLocationOnScreen( originalPos );
layoutMoved = originalPos[0]+icons.getWidth();
TranslateAnimation anim = new TranslateAnimation( 0, -layoutMoved , 0, 0);
anim.setDuration(500);
anim.setFillAfter( true );
icons.startAnimation(anim);
icons.setVisibility(View.GONE);
Set an AnimationListener, you'll have access to OnAnimationEnd.
anim.setAnimationListener(new Animation.AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {
}
#Override
public void onAnimationEnd(Animation animation) {
// do your stuff
}
#Override
public void onAnimationRepeat(Animation animation) {
}
});
i use this code for animate x and y position for view
the code
v.animate().x(margin).y(0).setDuration(200).start();
how can i call method when this animation finished
i have this code also i can by it call method when finished the animate
but i cant set x and y for View
ValueAnimator varl = ValueAnimator.ofInt(from,to);
varl.setDuration(200);
varl.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
#Override
public void onAnimationUpdate(ValueAnimator animation) {
}
});
varl.addListener(new AnimatorListenerAdapter()
{
#Override
public void onAnimationEnd(Animator animation)
{
// animate finish call method
}
});
varl.start();
i just thinking about make this code
v.animate().x(margin).y(0).setDuration(200).start();
inside the method onAnimationUpdate
i think its bad idea any another solution
Looks like the base class has a listener.
ObjectAnimator anim = ObjectAnimator.ofFloat(view, "alpha", 0.0f);
anim.addListener(new AnimatorListener() {
...
#Override
public void onAnimationEnd(Animator animation) {
// Do something.
}
...
});
anim.setDuration(300).start();
I want to vibrate a view with scaleX and scaleY, and I am doing it with this code, but the problem is that sometimes the view is not correctly reset, and it shows with the scale applied...
I want that when the animation ends, the view must be seen with its original status always
this is the code:
ObjectAnimator scaleX = ObjectAnimator.ofFloat(view, "scaleX", 1f, 0.9f);
scaleX.setDuration(50);
scaleX.setRepeatCount(5);
scaleX.setRepeatMode(Animation.REVERSE);
ObjectAnimator scaleY = ObjectAnimator.ofFloat(view, "scaleY", 1f, 0.9f);
scaleY.setDuration(50);
scaleY.setRepeatCount(5);
scaleY.setRepeatMode(Animation.REVERSE);
set.play(scaleX).with(scaleY);
set.start();
Thanks
For ValueAnimator and ObjectAnimator can be like this a try:
animator.addListener(new AnimatorListenerAdapter() {
#Override
public void onAnimationEnd(Animator animation) {
animation.removeListener(this);
animation.setDuration(0);
((ValueAnimator) animation).reverse();
}
});
UPDATE
On Android 7 it doesn't work.
Best way use the interpolator.
public class ReverseInterpolator implements Interpolator {
private final Interpolator delegate;
public ReverseInterpolator(Interpolator delegate){
this.delegate = delegate;
}
public ReverseInterpolator(){
this(new LinearInterpolator());
}
#Override
public float getInterpolation(float input) {
return 1 - delegate.getInterpolation(input);
}
}
In your code
animator.addListener(new AnimatorListenerAdapter() {
#Override
public void onAnimationEnd(Animator animation) {
animation.removeListener(this);
animation.setDuration(0);
animation.setInterpolator(new ReverseInterpolator());
animation.start();
}
});
According to the docs(Property Animation):
The property animation system can animate Views on the screen by changing the actual properties in the View objects. In addition, Views also automatically call the invalidate() method to refresh the screen whenever its properties are changed.
so you can use AnimatorListener to listen the animation event, then just reset the view property you animate. let's say cancel event and scaleX property:
scaleAnimator.setListener(new AnimatorListenerAdapter() {
#Override
public void onAnimationCancel(Animator animation) {
scaleView.setScaleX(0)
}
});
Hope this can help a bit.
You can add an AnimatorListener, to be notified when the animation ends:
scaleY.addListener(new AnimatorListener() {
#Override
public void onAnimationEnd(Animator animation) {
// TODO Restore view
}
#Override
public void onAnimationStart(Animator animation) {
}
#Override
public void onAnimationRepeat(Animator animation) {
}
#Override
public void onAnimationCancel(Animator animation) {
}
});
i'd like to make a translateAnimation in my Android app with the code below :
TranslateAnimation anim = new TranslateAnimation(0,0,-400,0);
anim.setDuration(400);
anim.setAnimationListener(new AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {
}
#Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
#Override
public void onAnimationEnd(Animation animation) {
mlLinearLayout.clearAnimation();
mlLinearLayout.requestLayout();
mlLinearLayout.layout(mlLinearLayout.getLeft(), mlLinearLayout.getTop()+400, mlLinearLayout.getRight(), mlLinearLayout.getBottom());
}
});
anim.setInterpolator(new AccelerateInterpolator());
anim.setFillEnabled(true);
anim.setFillAfter(true);
anim.setFillBefore(false);
mlLinearLayout.startAnimation(anim);
active=false;
but when this animation was done, the LinearLayout back to his start place even if I rebuild my view with the new position. How can I change it please ?
I finally found solution :
TranslateAnimation anim = new TranslateAnimation(0,0,0,400);
anim.setDuration(400);
anim.setAnimationListener(new AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {
}
#Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
#Override
public void onAnimationEnd(Animation animation) {
mlLinearLayout.layout(mlLinearLayout.getLeft(), mlLinearLayout.getTop()+400, mlLinearLayout.getRight(), mlLinearLayout.getBottom());
}
});
anim.setFillEnabled(true);
anim.setFillAfter(false);
anim.setFillBefore(false);
mlLinearLayout.startAnimation(anim);
active=false;
As i rebuild my view after translation, fillafter isn't usefull, Now it's working perfect without lag and jump !
Ok, so I have a View where its being animated with the following code:
RelativeLayout rl = (RelativeLayout) findViewById(R.id.productPage_parentLayout_RL);
ImageView iv = new ImageView( ProductPage.this );
imageLoader.DisplayImage(FULL_PRODUCT_INFO.getFirstImage(), iv);
Animation animation = new TranslateAnimation(0, helper.getDeviceWidth() - 100,0, 0);
animation.setDuration(1000);
animation.setFillAfter(true);
rl.addView(iv);
With this code, the view starts from the left side of the screen and moves to almost the end of the screen, but I also want to fade-out the view and hide/destroy it in the end. I tried to search anything related to this, but couldn't find any.
Any help is appreciated.
Try this
ObjectAnimator move=ObjectAnimator.ofFloat(iv, "translationY",100f);
move.setDuration(3000);
ObjectAnimator alpha1=ObjectAnimator.ofFloat(iv, "alpha",0.5f);
alpha1.setDuration(1000);
ObjectAnimator alpha2=ObjectAnimator.ofFloat(iv, "alpha",0);
alpha2.setDuration(2000);
AnimatorSet animset=new AnimatorSet();
animset.play(alpha2).before(alpha1).with(move);
animset.start();
Animation a = new AlphaAnimation(1.0f, 0.0f);
a.setDuration(1000);
a.setFillAfter(true);
iv.startAnimation(a);
AnimationSet set = new AnimationSet(true);
set.addAnimation(animation)
set.addAnimation(a)
set.setFillAfter(true);
iv.startAnimation(set);
set.setAnimationListener(new AnimationListener() {
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
public void onAnimationEnd(Animation animation) {
iv.setVisibility(View.INVISIBLE);
}
});