2016-06-23 1 views
3

두 프레임짜리 애니메이션 (animation-list)이 있습니다. 그 중 하나를 ImageView에로드하는 것은 문제가되지 않습니다. 문제는 동일한 ImageView에서 다른 애니메이션을로드하려고 할 때 발생합니다.
안드로이드에서 복수의 프레임 별 애니메이션을 하나씩로드하려고 할 때 OutOfMemoryError가 발생했습니다.

private void startAnimation(int anim) { 
    mImageView.setImageResource(anim); 
    ((AnimationDrawable) mImageView.getDrawable()).start(); 
} 

이것은 내가 사용하고있는 코드입니다. 함수를 두 번 이상 호출 한 후 java.lang.OutOfMemoryError을 얻은 후 다음 코드를 추가하여 AnimationDrawableImageView을 지우려고했습니다.

private void startAnimation(int anim) { 
    if (mImageView.getDrawable() != null) { //trying to clear if it's not empty 
     if (((AnimationDrawable) mImageView.getDrawable()).isRunning()) { 
      ((AnimationDrawable) mImageView.getDrawable()).stop(); 
      ((AnimationDrawable) mImageView.getDrawable()).selectDrawable(0); 
     } 
     mImageView.setImageResource(null); 
    } 
    //starting animation here 
    mImageView.setImageResource(anim); 
    ((AnimationDrawable) mImageView.getDrawable()).start(); 
} 

글쎄, 이것은 작동하지 않았다. 난 herehere 게시 솔루션을 시도하고 그들은 또한 작동하지 않았다. 나는 아직도 계속 OutOfMemoryError을 얻고있다.

이렇게하면 startAnimation 함수를 호출합니다.

startAnimation(R.drawable.anim1);//works fine 
startAnimation(R.drawable.anim2);//OutOfMemoryError 
... 

그래서 어떻게 메모리를 비우고 애니메이션을로드합니까? 나는 이것을 계속 반복하고 싶다.

+0

가비지 컬렉터가 앱이 새로운 애니메이션을로드 할 때 오래된 애니메이션 리소스를 제거한다고 생각합니다. –

+0

또한'System.gc()'를 사용하지 않으려했습니다. 너는 무엇을 제안 하는가? – Kidus

+0

Imma 죄송합니다, 해결책을 찾을 수있는 컴퓨터가 없습니다. 가능한 버그 이유를 썼습니다. –

답변

0

새 애니메이션을 시작하기 전에 마침내 mImageView.getDrawable().setVisible(false, true)을 추가하여 작동하도록했습니다.

관련 문제