Animation Drawable causing OutOfMemoryError on second run in Android

前端 未结 5 1145
傲寒
傲寒 2020-12-05 11:57

I am currently developing a game and I\'m trying to use one AnimationDrawable to show one animation in my Main Menu. When I run the game once, it works perfectly. But if i t

5条回答
  •  难免孤独
    2020-12-05 12:53

    You can try by reducing the size if images. My case it worked.

    int[] frames = {R.drawable.frame1, R.drawable.frame2, R.drawable.frame3};
    AnimationDrawable drawable = new AnimationDrawable();
        for (int fr : frames) {
            Bitmap sample = BitmapFactory.decodeResource(mActivity.getResources(), fr);
            sample = Bitmap.createScaledBitmap(sample, sample.getWidth()/4, sample.getHeight()/4, false);
            drawable.addFrame(new BitmapDrawable(mActivity.getResources(), sample), 30);
        }
    

提交回复
热议问题