In my application , i m applying an animation on layout. This animation put the layout off the screen and put it in from the other side :
private void slideAnimation(final int sens)
{
Animation animOut = null;
if(sens == -1) {
animOut = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.slide_out_left);
} else {
animOut = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.slide_out_right);
}
animOut.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 animIn = null;
if(sens == -1) {
animIn = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.slide_in_right);
} else {
animIn = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.slide_in_left);
}
camLayout.startAnimation(animIn);
}
});
camLayout.startAnimation(animOut);
}
When needed i simply call slideAnimation().
It’s working fine , but sometime we can see animation in a runnable. Should i consider using an other solution to slide out and in my layout or my code is OK ?
Thanks
seems ok to me! I gather you are just trying to schedule one animation to play after the another. And this code will do the job. I am not sure but i suppose the animation end listener does already listen from a different thread. So i don’t think a new thread is required.