我是新來的Android以下this在Android中創建一個MEME應用程序的教程一切都工作正常,直到我添加圖像到我的RelativeLayout背景的一個fragement。OutOfMemory異常佈局的背景圖像
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:background="@drawable/dp"
android:id="@+id/imageOut">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/topText"
android:id="@+id/topMemeText"
android:layout_marginTop="32dp"
android:textColor="#FFF"
android:gravity="center_horizontal"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/bottomText"
android:id="@+id/bottomMemeText"
android:layout_marginBottom="69dp"
android:textColor="#FFF"
android:gravity="center_horizontal"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
錯誤是
Caused by: java.lang.OutOfMemoryError: Failed to allocate a 86687164 byte allocation with 1048576 free bytes and 63MB until OOM
我知道,這個問題是由於圖像大小和我的,因爲我在網上搜索也有很多情況下,將其解碼並在這裏http://developer.android.com/training/displaying-bitmaps/load-bitmap.html。但everycase我來了跨使用ImageView,但我有一個佈局的背景圖像,而不是一個ImageView,所以我怎麼才能從佈局獲取ImageView對象,以便我可以使用。
mImageView.setImageBitmap(
decodeSampledBitmapFromResource(getResources(), R.id.myimage, 100, 100));
感謝
您使用的圖像的像素大小是多少? –
大小是'262kb'我知道如果我使用小尺寸圖片的概率可能會解決,但我怎樣才能處理它與像素的代碼'1790 x 1757' – codegasmer
但是,像素的大小是多少(圖像的尺寸) ? –