Lennie
Lennie

Reputation: 2069

Android layer images

I draw a set of images on-top of each other similar to http://webhelp.esri.com/arcgisserver/9.3/java/geodatabases/data_themes_as_layers.gif where each image have transparent areas and a area that is clickable. The idea is to have a image of a vehicle with clickable areas, off course some areas aren't clickable which are transparent.

Each image is a different formats: HDPI, MDPI, XHDPI, XXHDPI, XXXHDPI. When render it cause a crash on some device since it run out of memory so obviously am doing something wrong here or the images are too big? I did check the size of the images and they all according to specification.

Layout that i use:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/ScreenLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <ImageView
        android:id="@+id/BASE"
        android:tag="-1"
        android:src="@drawable/car_base_right"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
    <ImageView
        android:id="@+id/car_B1"
        android:tag="0"
        android:background="@android:color/transparent"
        android:src="@drawable/car_B1_green"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
    <ImageView
        android:id="@+id/car_B2"
        android:tag="0"
        android:background="@android:color/transparent"
        android:src="@drawable/car_B2_green"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
    <ImageView
        android:id="@+id/car_B3"
        android:tag="0"
        android:background="@android:color/transparent"
        android:src="@drawable/car_B3_green"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
    <ImageView
        android:id="@+id/car_B4"
        android:tag="0"
        android:background="@android:color/transparent"
        android:src="@drawable/car_B4_green"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
    <ImageView
        android:id="@+id/car_B5"
        android:tag="0"
        android:background="@android:color/transparent"
        android:src="@drawable/car_B5_green"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
    <ImageView
        android:id="@+id/car_B6"
        android:tag="0"
        android:background="@android:color/transparent"
        android:src="@drawable/car_B6_green"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
    <ImageView
        android:id="@+id/car_B7"
        android:tag="0"
        android:background="@android:color/transparent"
        android:src="@drawable/car_B7_green"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
    <ImageView
        android:id="@+id/car_B8"
        android:tag="0"
        android:background="@android:color/transparent"
        android:src="@drawable/car_B8_green"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
    <ImageView
        android:id="@+id/car_B9"
        android:tag="0"
        android:background="@android:color/transparent"
        android:src="@drawable/car_B9_green"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
    <ImageView
        android:id="@+id/car_B10"
        android:tag="0"
        android:background="@android:color/transparent"
        android:src="@drawable/car_B10_green"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
    <ImageView
        android:id="@+id/car_B11"
        android:tag="0"
        android:background="@android:color/transparent"
        android:src="@drawable/car_B11_green"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</FrameLayout>

Upvotes: 1

Views: 50

Answers (1)

IntelliJ Amiya
IntelliJ Amiya

Reputation: 75788

You are dealing with large images and loading all of them at run time. You have to deal very carefully with large images by loading the size that you need not the whole images at once and then do scaling.

Solutions

  1. Reduce image size & resolutions .
  2. android:largeHeap=”true” flags in manifest file.

Upvotes: 2

Related Questions