-1

我正在开发一个应用程序,它显示一个列表视图,其中包含在用户单击它们时编辑的不同图像。

这是我的 row.xml 文件的代码。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >

 <ImageView
    android:id="@+id/imageView1"
    android:layout_width="80dp"
    android:layout_height="80dp"/>

 <TextView
     android:id="@+id/textView1"
     android:layout_marginTop="20dp"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:gravity="center_vertical"
     android:layout_marginLeft="8dp"
     android:text="TextView" 
     android:textSize="25sp"


     />

我只使用一组图像,存储在文件夹 res/drawable/drawable-nodpi 中(因为我需要它们保持其原始大小以便将它们编辑为位图)。

问题是这些图像太大也显示在单个活动中,因此,当我创建列表视图时,它使用大量内存并且列表滚动时有一些滞后。如何在没有此问题的情况下在列表中显示这些图像?我应该创建另一组较小的图像以在列表中使用它们吗?当应用程序将图像保存到 SD 卡或缓存时,我已经阅读过帖子,但实际上我不确定最适合我的特定应用程序的解决方案。

提前致谢

4

4 回答 4

0

您可以使用下面的链接来制作您的清单。在这里,一旦看不到图像缓存,他们就会释放它。使用它,您可以将许多图像放入您的列表中:

https://github.com/thest1/LazyList

希望这对您有所帮助。

于 2014-03-14T04:16:50.947 回答
0

试试这个.. Android-Universal-Image-Loader 库。该项目旨在为异步图像加载、缓存和显示提供可重用的工具。它最初是基于 Fedor Vlasov 的项目,并从那时起进行了大量的重构和改进。

https://github.com/nostra13/Android-Universal-Image-Loader

对于可绘制资源,请使用此..

字符串 imageUri = "drawable://" + R.drawable.image; // 来自可绘制对象(仅限图像,非 9patch)

于 2014-03-14T04:17:30.063 回答
0

我建议你使用 Aquery 来下载图片。只需从此链接下载 jarfile

如何使用 :

AQuery _aq = new AQuery(youractivity context);

//fetch and set the image from internet, cache with file and memory 
aq.id(R.id.your_imageview_object).image("http://www.vikispot.com/z/images/vikispot/android-w.png");
于 2014-03-14T04:25:20.287 回答
0

我认为这些方法可能会有所帮助:

  1. 将这些图像放入服务器,然后使用通用图像加载器加载它。通用图像加载器已经解决了这个问题。你可以试试这个项目https://github.com/dodola/Android-Universal-Image-Loader

  2. 如果您必须将这些图像放在 res 中,我认为您可以实现自己的图像加载器。在您的图像加载器中,您必须使用软引用将图像缓存在内存中。这是另一个问题。

于 2014-03-14T04:21:35.730 回答