我是新来的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
但是,像素的大小是多少(图像的尺寸) ? –