小编Jot*_*ito的帖子

来自AnimationDrawable的可用内存

我在我的应用程序的许多活动中使用animationdrawables.这是对他们进行初步化的代码:

 public void prepareVideo (int resourceBall, String animation, int width, int height ){

    imgBall = (ImageView)findViewById(resourceBall);
    imgBall.setVisibility(ImageView.VISIBLE);
    String resourceNameAnimation = animation;
    int id_res = getResources().getIdentifier(resourceNameAnimation, "drawable", getPackageName());
    imgBall.setBackgroundResource(id_res);
        LayoutParams latoutFrame = imgBall.getLayoutParams();
    latoutFrame.width = width;
    latoutFrame.height = height;
    imgBall.setLayoutParams(latoutFrame); 
    frame = (AnimationDrawable) imgBall.getBackground();


}
Run Code Online (Sandbox Code Playgroud)

然后我调用:imgBall.post(new StartAnimation());

调用runnable:

class StartAnimation implements Runnable {

    public void run() {

frame.start();

    }

}
Run Code Online (Sandbox Code Playgroud)

问题是我使用了许多动画,它们使用相同的xml(逐帧).我必须在具有相同动画的许多活动中调用此方法.最后,我得到了一个错误的错误.我试图在屏幕之间释放内存:

for (int i = 0; i < frame.getNumberOfFrames(); ++i){
     Drawable frame_rescue = frame.getFrame(i);
     if (frame_rescue instanceof BitmapDrawable) {
         ((BitmapDrawable)frame_rescue).getBitmap().recycle();
     } …
Run Code Online (Sandbox Code Playgroud)

android animationdrawable

5
推荐指数
1
解决办法
1486
查看次数

标签 统计

android ×1

animationdrawable ×1