如何使用高分辨率图像减少图像视图所占用的内存?

时间:2012-06-19 17:50:42

标签: android memory imageview

我在ImageView中将以下Image作为src。我用它作为背景图像。 这使我的应用程序内存从~5MB增长到~20M。

enter image description here

这是使用此图像的代码:(android:id =“@ + id / listViewBackground”是我正在谈论的imageview)

    <RelativeLayout
    android:id="@+id/ContentLayout"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/ButtonsMenu"
    android:background="@android:color/transparent" >

    <ImageView
        android:id="@+id/listViewBackground"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@android:color/transparent"
        android:scaleType="center"            
        android:src="@drawable/background" />

    <LinearLayout
        android:id="@+id/header"
        android:layout_width="fill_parent"
        android:layout_height="50dp"
        android:background="@android:color/transparent" >

        <TextView
            android:id="@+id/leftHeader"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@drawable/button_green"
            android:gravity="center"
            android:text="@string/Title_BatteryLevel"
            android:textColor="@android:color/white" />

        <TextView
            android:id="@+id/rightHeader"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@drawable/button_blue"
            android:gravity="center"
            android:text="@string/Title_Duration"
            android:textColor="@android:color/white" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/AdLayout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:background="@android:color/transparent" >
    </LinearLayout>

    <ListView
        android:id="@+id/listView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_above="@id/AdLayout"
        android:layout_below="@id/header"
        android:background="@android:color/transparent"
        android:cacheColorHint="#00000000"
        android:clickable="false"
        android:focusable="false"
        android:focusableInTouchMode="false"
        android:listSelector="@android:color/transparent"
        android:paddingBottom="5dp" >
    </ListView>
</RelativeLayout>

我需要这个图像到不同的屏幕尺寸,所以它的高分辨率。 我也希望看到这些线条。

如何减少应用占用的内存?

1 个答案:

答案 0 :(得分:2)

首先,将图像缩小到可重复的部分。

其次,请按照本教程了解如何将背景图像应用于视图(在本例中为相对布局“listViewBackground”)http://androidforbeginners.blogspot.com/2010/06/how-to-tile-background-image-in-android.html