【问题标题】:How can I reduce the memory taken by ImageView with hight resolution image?如何减少具有高分辨率图像的 Image View 占用的内存?
【发布时间】:2012-06-19 17:50:41
【问题描述】:

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

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

    <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>

我需要这张图片适应不同的屏幕尺寸,所以它的分辨率很高。 我也希望能看到这些线条。

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

【问题讨论】:

    标签: android memory imageview


    【解决方案1】:

    首先,将您的图像缩减为仅可重复的部分。

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

    【讨论】:

      猜你喜欢
      • 2012-12-23
      • 1970-01-01
      • 1970-01-01
      • 2014-11-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多