1

Basically, I have an AnimationDrawable that I generated with a helper method:

public static AnimationDrawable requestLoadingDrawable(Context originContext) {
        if(panoramaLoadingLoopDrawable == null) {
            panoramaLoadingLoopDrawable = new AnimationDrawable();
            Bitmap src = BitmapFactory.decodeResource(originContext.getResources(), R.drawable.load360_3lines);
            BitmapDrawable frameInDrawable;
            //int squareInstDim = (int)(200*adapterCtx.getResources().getDisplayMetrics().density);
            int horiDim = (int)(src.getWidth() / 10);
            int vertDim = (int)(src.getHeight() / 3);
            Bitmap frame;
            for(int i = 0; i < 3; i++) {
                for(int j = 0; j < 10; j++) {
                    frame = Bitmap.createBitmap(src, j * horiDim, i*vertDim, horiDim, vertDim);
                    frameInDrawable = new BitmapDrawable(originContext.getResources(), frame);
                    panoramaLoadingLoopDrawable.addFrame(frameInDrawable, (1000/30));
                }
            }
            src.recycle();
        }
        panoramaLoadingLoopDrawable.setOneShot(false);
        return panoramaLoadingLoopDrawable;
    }

The panoramaLoadingLoopDrawable is private static in this helper class.

When I put it in the RecyclerView, when there's 2 items that use this AnimationDrawable in the ViewHolder, both would stop animating.

Should I make the panoramaLoadingLoopDrawable non-static or something?

Gensoukyou1337
  • 1,507
  • 1
  • 13
  • 31
  • The problem is that your `panoramaLoadingLoopDrawable ` is Singleton. So you are using same animation drawable for both views. You should return new instance for every `RecyclerView` item. – Vygintas B Dec 21 '17 at 05:28

0 Answers0