상황입니다. 세 가지 레이아웃으로 된 ViewAnimator가 있습니다. 각 레이아웃에는 서로 다른 배경 이미지가 있습니다. xhdpi 장치의 경우 이미지 크기는 1280x800 픽셀이며 크기는 ~ 150KB입니다. 이제 문제 :Android ViewAnimator 및 OutOfMemoryError
09-02 08:22:46.408: D/dalvikvm(1291): GC_EXTERNAL_ALLOC freed 428K, 51% free 2874K/5831K, external 18484K/20407K, paused 83ms
09-02 08:22:46.419: E/dalvikvm-heap(1291): 1366400-byte external allocation too large for this process.
09-02 08:22:46.498: I/dalvikvm-heap(1291): Clamp target GC heap from 25.089MB to 24.000MB
09-02 08:22:46.498: E/GraphicsJNI(1291): VM won't let us allocate 1366400 bytes
09-02 08:22:49.208: E/AndroidRuntime(1291): java.lang.OutOfMemoryError: bitmap size exceeds VM budget
아무도 내 문제에 대한 해결책이나 해결 방법을 가지고 : 나는 화면 1280x800의 크기와 320dp의 밀도와 에뮬레이터를 시작할 때, 나는 항상이 예외가 발생? BitmapFactory에 대해 읽어 보았습니다. 도움이 되나요? 최고 감사합니다! 편집
: 레이아웃 파일 main_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical" >
<ViewAnimator
android:id="@+id/viewAnimator"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="@+id/LayoutMain"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
android:background="@drawable/background"
...some Buttons etc. ...
</LinearLayout>
<LinearLayout
android:id="@+id/layoutGameMenu"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
android:background="@drawable/gameMenu"
...some Buttons etc. ...
</LinearLayout>
<LinearLayout
android:id="@+id/layoutHighscores"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/highscores"
...some ListViews etc. ...
</LinearLayout>
</ViewAnimator>
</LinearLayout>
그리고 MainActivity : 여기 내 코드 나는 MAINMENU 사이를 전환 할 수 있습니다,이와
private ViewAnimator va;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_layout);
va = (ViewAnimator) findViewById(R.id.viewAnimator);
....
}
....
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if(event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
if (va.getCurrentView() == findViewById(R.id.layoutHighscores)) {
va.setInAnimation(inFromRight);
va.setOutAnimation(outToLeft);
va.setDisplayedChild(0);
return true;
}
if (va.getCurrentView() == findViewById(R.id.layoutGameMenu)) {
va.setInAnimation(inFromLeft);
va.setOutAnimation(outToRight);
va.setDisplayedChild(0);
return true;
}
}
return super.onKeyDown(keyCode, event);
}
, 최고 기록 gamemode를 시작하는 버튼이있는 gamemenu가 있습니다. "시원한"뷰 애니메이션을 원하기 때문에 이것을 선택합니다.
BitmapFactory 메서드로 해결하려고 시도했지만 변경된 사항이 없습니다.
public static Bitmap decodeSampledBitmapFromResource(Resources res, int resId, int reqWidth, int reqHeight) {
// First decode with inJustDecodeBounds=true to check dimensions
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeResource(res, resId, options);
// Calculate inSampleSize
options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
// Decode bitmap with inSampleSize set
options.inJustDecodeBounds = false;
return BitmapFactory.decodeResource(res, resId, options);
}
public static int calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight) {
// Raw height and width of image
final int height = options.outHeight;
final int width = options.outWidth;
int inSampleSize = 1;
if (height > reqHeight || width > reqWidth) {
if (width > height) {
inSampleSize = Math.round((float)height/(float)reqHeight);
} else {
inSampleSize = Math.round((float)width/(float)reqWidth);
}
}
return inSampleSize;
}
실제 기기를 사용해 보셨나요? – wtsang02
아니요,이 크기의 장치가 없습니다. 그래서 에뮬레이터에서 시험해보아야합니다. – Namenlos