0

I have a problem with my app. My activity consists of the following xml code:

<ScrollView
    android:id="@+id/main_scroll"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <LinearLayout
        android:id="@+id/layout_container"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:paddingLeft="16sp"
        android:paddingRight="16sp"
        android:paddingTop="16sp" >
    </LinearLayout>
</ScrollView>

Using inflate, insert the LinearLayout containing images .png! This causes Grow heap (frag case). There is a method to reduce grow the heap, maintaining this setup?

This is the Layout inserted in MainActivity:

<LinearLayout
    android:id="@+id/layout_scheda_serie"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/text_scheda_nome"
        style="?android:textAppearanceLarge"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textStyle="italic" />
</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="?android:selectableItemBackground"
    android:orientation="horizontal" >

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:gravity="center"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/text_scheda_simbolo"
            style="?android:textAppearanceLarge"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="25sp"
            android:textStyle="italic" />

        <TextView
            android:id="@+id/text_scheda_numero"
            style="?android:textAppearanceLarge"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="25sp"
            android:textStyle="italic" />

        <TextView
            android:id="@+id/text_scheda_massa"
            style="?android:textAppearanceSmall"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="@android:color/secondary_text_light_nodisable" />

        <TextView
            android:id="@+id/text_scheda_ossidazione"
            style="?android:textAppearanceSmall"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="@android:color/secondary_text_light_nodisable" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:gravity="right"
        android:orientation="vertical"
        android:padding="5sp" >

        <com.chElem.RecyclingImageView
            android:id="@+id/imageView_scheda_foto"
            android:layout_width="165sp"
            android:layout_height="165sp"
            android:src="?android:selectableItemBackground" />
    </LinearLayout>
</LinearLayout>

Thanks!

4

1 回答 1

0

If I understand your question correctly then the answer unfortunately is no, you can't avoid this.

When you load the layout of your Activity and several images into memory it's inevitable that the heap usage will grow.

于 2013-05-16T10:52:27.560 回答