Feroz Siddiqui Feroz Siddiqui - 1 month ago 6
Android Question

How to add animation on an Imageview after the image has been loaded from Piccasso inside fragment of viewpager

How to add animation on an Imageview after the image has been loaded from Piccasso inside fragment of viewpager. the viewpager Adapter is not destroying any fragment as per below code:

@Override
public void destroyItem(ViewGroup container, int position, Object object) {
// TODO Auto-generated method stub
}


in which super is not getting called.

below is code for imageview which is not working

ImageView image = (ImageView) view.findViewById(R.id.image);

mPicasso.load("ImageUrl").into(image);

Animation slide_down = AnimationUtils.loadAnimation(getContext(),
R.anim.slide_up);
slide_down.setDuration(400);
image.startAnimation(slide_down);


if i do something like this

Animation slide_down = AnimationUtils.loadAnimation(getContext(),
R.anim.slide_up);
slide_down.setDuration(1000);
slide_down.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
mPicasso.load("ImageUrl").into(image);

}

@Override
public void onAnimationEnd(Animation animation) {

}

@Override
public void onAnimationRepeat(Animation animation) {

}
});
image.startAnimation(slide_down);


The animation is working for first time not the second time since viewpager is not destroying the fragment

Answer

Try

mPicasso.load("ImageUrl").into(image new Callback() {
                @Override
                public void onSuccess() {
                  image.startAnimation(slide_down);
                }

                @Override
                public void onError() {

                }
            })

Define you animation first.