1

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

  • you have to use `into` method with an `ImageView` and `Callback` parameters – pskink Nov 01 '16 at 17:19
  • what should i do with viewpager since its the only fragment i have to preserve the state of fragment so thats why not destrying its fragment. I have 40 different fragment for which i have save the state call same animation but its getting called for first one only. –  Nov 01 '16 at 17:22
  • 1
    you have to start your animation from the "finish" `Callback` – pskink Nov 01 '16 at 17:24
  • can you please post this as answer to accept –  Nov 01 '16 at 17:27
  • http://stackoverflow.com/questions/34488556/fade-in-animation-while-loading-image-using-picasso – jignesh.world Nov 02 '16 at 04:52

1 Answers1

0

Try

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

                @Override
                public void onError() {

                }
            })

Define you animation first.

Marco Pierucci
  • 1,125
  • 8
  • 23