我正在使用NestedScrollView
作为我的布局来显示TextView
作为标题与HorizontalScrollView
以显示可滑动的图片。
下面是一个例子:Android:如何解决OutOfMemoryError
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="none"
android:layout_weight="1">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
android:textStyle="bold"
android:text="Cable Crunches"
android:id="@+id/cableCrunches"
android:gravity="center"
android:padding="3dp"
android:textSize="18sp"/>
<HorizontalScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/cableCrunches"
android:id="@+id/cableCrunchesPics">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/cableCrunchesPics1"
android:src="@drawable/cable_crunches_1"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/cableCrunchesPics2"
android:src="@drawable/cable_crunches_2"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/cableCrunchesPics3"
android:src="@drawable/cable_crunches_3"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/cableCrunchesPics4"
android:src="@drawable/cable_crunches_4"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/cableCrunchesPics5"
android:src="@drawable/cable_crunches_5"/>
</LinearLayout>
</HorizontalScrollView>
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
的TextView
和HorizontalScrollView
块使用大约15倍于我的布局,并与这个设计我有一个OutOfMemoryError异常。
当我使用较少的块时,错误不会出现。
我试图尽量减少我的PNG文件的大小,但这并不能解决问题。
是否有任何其他布局我可以使用并不是所有的ImageView
在应用程序的开始加载?
使用picasso库在您的布局中显示图像 –