I'm using RecyclerView and CardView for my layout and want to display a watermark which spans across 4 cards on the screen. I've chopped up the watermark image into 4 separate images, one for each card (each image already has the dimensions I want it to be displayed with). To display the images, I am using ImageView inside of each card's .xml file as such:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/cardview"
android:layout_width="415dp"
android:layout_height="89dp"
android:layout_marginTop="0dp"
android:elevation="100dp"
card_view:cardBackgroundColor="#ffffff">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="@drawable/watermark_card1"
android:scaleType="centerCrop" />
.
.
.
</RelativeLayout>
</android.support.v7.widget.CardView>
This works fine while I am only loading 2 out of the 4 images, but when I load the 3rd one, I get the following error:
java.lang.OutOfMemoryError: Failed to allocate a 210446976 byte allocation with 4194304 free bytes and 101MB until OOM
I believe that this is because the images are all very large (521K, 976K, 611K, and 933K) and I am wondering what I could do to use less memory and avoid the OutOfMemory Error. Any advice would be appreciated, thanks!