I am using an NestedScrollView
for my layout to display a TextView
as a header with a HorizontalScrollView
to display slidable pictures.
Here is an example:
<?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>
The TextView
and the HorizontalScrollView
block are used around 15 times in my layout and with this design I've got a OutOfMemoryError.
When I use less of those blocks the error doesn´t appear.
I've tried to minimize the size of my PNG files, but this doesn't solve the problem.
Is there any other layout I could use were not all ImageView
are loaded at the start of the app?