0

现在我有一些类负责保存内部内存位图,然后在 ListViews 中列出。

列出后,诉诸一种方法,告诉您要返回的图像名称并接收相应的位图。

当应用程序启动时,将您需要的所有图像加载到内存(HashMap)中,一旦将图像从内部存储器直接加载到列表视图,该过程需要很长时间。

我正在使用视图的回收,每个项目都有两个和两个图像视图文本视图。但是,滚动非常慢并且有很多滞后。

将图像保存在内存中(哈希图)是一个很好的解决方案吗?对于在列表时加载到内存中的速度更慢。图像有 100x100 像素。

我的问题是:我的延迟问题可能与图像都在内存中这一事实有关?什么是最好的解决方案?

编辑:

07-25 16:56:33.195: V/ADAPTER(8648): recicling view [1]
07-25 16:56:33.195: V/ADAPTER(8648): recicling view [2]
07-25 16:56:33.203: V/ADAPTER(8648): recicling view [3]
07-25 16:56:33.203: V/ADAPTER(8648): recicling view [4]
07-25 16:56:33.210: V/ADAPTER(8648): recicling view [5]
07-25 16:56:33.257: V/ADAPTER(8648): recicling view [16]
07-25 16:56:33.265: V/ADAPTER(8648): recicling view [15]
07-25 16:56:33.273: V/ADAPTER(8648): recicling view [14]
07-25 16:56:33.281: V/ADAPTER(8648): recicling view [0]
07-25 16:56:33.289: V/ADAPTER(8648): recicling view [1]
07-25 16:56:33.289: V/ADAPTER(8648): recicling view [2]
07-25 16:56:33.289: V/ADAPTER(8648): recicling view [3]
07-25 16:56:33.296: V/ADAPTER(8648): recicling view [4]
07-25 16:56:33.296: V/ADAPTER(8648): recicling view [5]
07-25 16:56:33.304: V/ADAPTER(8648): recicling view [6]
07-25 16:56:33.312: V/ADAPTER(8648): recicling view [7]
07-25 16:56:33.320: V/ADAPTER(8648): recicling view [0]
07-25 16:56:33.328: V/ADAPTER(8648): recicling view [1]
07-25 16:56:33.328: V/ADAPTER(8648): recicling view [2]
07-25 16:56:33.335: V/ADAPTER(8648): recicling view [3]
07-25 16:56:33.335: V/ADAPTER(8648): recicling view [4]
07-25 16:56:33.343: V/ADAPTER(8648): recicling view [5]
07-25 16:56:33.343: V/ADAPTER(8648): recicling view [6]
07-25 16:56:33.359: V/ADAPTER(8648): recicling view [0]
07-25 16:56:33.359: V/ADAPTER(8648): recicling view [1]
07-25 16:56:33.367: V/ADAPTER(8648): recicling view [2]
07-25 16:56:33.367: V/ADAPTER(8648): recicling view [3]
07-25 16:56:33.367: V/ADAPTER(8648): recicling view [4]
07-25 16:56:33.375: V/ADAPTER(8648): recicling view [5]
07-25 16:56:33.382: V/ADAPTER(8648): recicling view [6]
07-25 16:56:33.398: V/ADAPTER(8648): recicling view [0]
07-25 16:56:33.398: V/ADAPTER(8648): recicling view [1]
07-25 16:56:33.406: V/ADAPTER(8648): recicling view [2]
07-25 16:56:33.406: V/ADAPTER(8648): recicling view [3]
07-25 16:56:33.414: V/ADAPTER(8648): recicling view [4]
07-25 16:56:33.414: V/ADAPTER(8648): recicling view [5]
07-25 16:56:33.484: V/ADAPTER(8648): recicling view [13]
07-25 16:56:33.492: V/ADAPTER(8648): recicling view [0]
07-25 16:56:33.500: V/ADAPTER(8648): recicling view [1]
07-25 16:56:33.500: V/ADAPTER(8648): recicling view [2]
07-25 16:56:33.507: V/ADAPTER(8648): recicling view [3]
07-25 16:56:33.507: V/ADAPTER(8648): recicling view [4]
07-25 16:56:33.507: V/ADAPTER(8648): recicling view [5]
07-25 16:56:33.515: V/ADAPTER(8648): recicling view [6]
07-25 16:56:33.523: V/ADAPTER(8648): recicling view [7]
07-25 16:56:33.531: V/ADAPTER(8648): recicling view [0]
07-25 16:56:33.539: V/ADAPTER(8648): recicling view [1]
07-25 16:56:33.539: V/ADAPTER(8648): recicling view [2]
07-25 16:56:33.546: V/ADAPTER(8648): recicling view [3]
07-25 16:56:33.546: V/ADAPTER(8648): recicling view [4]
07-25 16:56:33.554: V/ADAPTER(8648): recicling view [5]
07-25 16:56:33.554: V/ADAPTER(8648): recicling view [6]
07-25 16:56:33.562: V/ADAPTER(8648): recicling view [0]
07-25 16:56:33.570: V/ADAPTER(8648): recicling view [1]
07-25 16:56:33.578: V/ADAPTER(8648): recicling view [2]
07-25 16:56:33.578: V/ADAPTER(8648): recicling view [3]
07-25 16:56:33.578: V/ADAPTER(8648): recicling view [4]
07-25 16:56:33.585: V/ADAPTER(8648): recicling view [5]
07-25 16:56:33.585: V/ADAPTER(8648): recicling view [6]
07-25 16:56:33.609: V/ADAPTER(8648): recicling view [0]
07-25 16:56:33.609: V/ADAPTER(8648): recicling view [1]
07-25 16:56:33.617: V/ADAPTER(8648): recicling view [2]
07-25 16:56:33.617: V/ADAPTER(8648): recicling view [3]
07-25 16:56:33.625: V/ADAPTER(8648): recicling view [4]
07-25 16:56:33.625: V/ADAPTER(8648): recicling view [5]
07-25 16:56:33.679: V/ADAPTER(8648): recicling view [12]
07-25 16:56:33.687: V/ADAPTER(8648): recicling view [0]
07-25 16:56:33.695: V/ADAPTER(8648): recicling view [1]
07-25 16:56:33.695: V/ADAPTER(8648): recicling view [2]
07-25 16:56:33.703: V/ADAPTER(8648): recicling view [3]
07-25 16:56:33.703: V/ADAPTER(8648): recicling view [4]
07-25 16:56:33.710: V/ADAPTER(8648): recicling view [5]
07-25 16:56:33.710: V/ADAPTER(8648): recicling view [6]
07-25 16:56:33.718: V/ADAPTER(8648): recicling view [7]
07-25 16:56:33.734: V/ADAPTER(8648): recicling view [0]
07-25 16:56:33.734: V/ADAPTER(8648): recicling view [1]
07-25 16:56:33.742: V/ADAPTER(8648): recicling view [2]
07-25 16:56:33.742: V/ADAPTER(8648): recicling view [3]
07-25 16:56:33.750: V/ADAPTER(8648): recicling view [4]
07-25 16:56:33.750: V/ADAPTER(8648): recicling view [5]
07-25 16:56:33.757: V/ADAPTER(8648): recicling view [6]
07-25 16:56:33.765: V/ADAPTER(8648): recicling view [0]
07-25 16:56:33.773: V/ADAPTER(8648): recicling view [1]
07-25 16:56:33.773: V/ADAPTER(8648): recicling view [2]
07-25 16:56:33.773: V/ADAPTER(8648): recicling view [3]
07-25 16:56:33.781: V/ADAPTER(8648): recicling view [4]
07-25 16:56:33.781: V/ADAPTER(8648): recicling view [5]
07-25 16:56:33.789: V/ADAPTER(8648): recicling view [6]
07-25 16:56:33.804: V/ADAPTER(8648): recicling view [0]
07-25 16:56:33.812: V/ADAPTER(8648): recicling view [1]
07-25 16:56:33.812: V/ADAPTER(8648): recicling view [2]
07-25 16:56:33.812: V/ADAPTER(8648): recicling view [3]
07-25 16:56:33.820: V/ADAPTER(8648): recicling view [4]
07-25 16:56:33.820: V/ADAPTER(8648): recicling view [5]
07-25 16:56:33.875: V/ADAPTER(8648): recicling view [0]
07-25 16:56:33.882: V/ADAPTER(8648): recicling view [1]
07-25 16:56:33.890: V/ADAPTER(8648): recicling view [2]
07-25 16:56:33.890: V/ADAPTER(8648): recicling view [3]
07-25 16:56:33.898: V/ADAPTER(8648): recicling view [4]
07-25 16:56:33.898: V/ADAPTER(8648): recicling view [5]
07-25 16:56:33.906: V/ADAPTER(8648): recicling view [6]
07-25 16:56:33.914: V/ADAPTER(8648): recicling view [7]
07-25 16:56:33.929: V/ADAPTER(8648): recicling view [0]
07-25 16:56:33.929: V/ADAPTER(8648): recicling view [1]
07-25 16:56:33.937: V/ADAPTER(8648): recicling view [2]
07-25 16:56:33.937: V/ADAPTER(8648): recicling view [3]
07-25 16:56:33.945: V/ADAPTER(8648): recicling view [4]
07-25 16:56:33.953: V/ADAPTER(8648): recicling view [5]
07-25 16:56:33.953: V/ADAPTER(8648): recicling view [6]
07-25 16:56:33.968: V/ADAPTER(8648): recicling view [0]
07-25 16:56:33.976: V/ADAPTER(8648): recicling view [1]
07-25 16:56:33.976: V/ADAPTER(8648): recicling view [2]
07-25 16:56:33.976: V/ADAPTER(8648): recicling view [3]
07-25 16:56:33.984: V/ADAPTER(8648): recicling view [4]
07-25 16:56:33.984: V/ADAPTER(8648): recicling view [5]
07-25 16:56:33.992: V/ADAPTER(8648): recicling view [6]
07-25 16:56:34.007: V/ADAPTER(8648): recicling view [0]
07-25 16:56:34.015: V/ADAPTER(8648): recicling view [1]
07-25 16:56:34.015: V/ADAPTER(8648): recicling view [2]
07-25 16:56:34.015: V/ADAPTER(8648): recicling view [3]
07-25 16:56:34.023: V/ADAPTER(8648): recicling view [4]
07-25 16:56:34.031: V/ADAPTER(8648): recicling view [5]

每当我滚动(列表继续)时,我都会得到这个输出。其中 [] 内的内容对应位置。他不断地显示0-6的位置是不是很奇怪?

编辑

现在发现了一个可能的原因。

我目前是一个 tab_activity,其中有所有必要的视图。在 xml 中添加了一个 tab_activity top_bar,其中我有一个不断更改的图像。当图像处于自动模式(不断更改)时,选项卡内的 ListViews 被“重新绘制”,因此存在滞后。

我正在使用一项服务(音乐),它会在 x 时间内改变 x 的图像。

为什么我查看重绘图像时要重绘 ListView?

4

1 回答 1

0

I'm not sure if the loading of the images is causing the lag, yet if it is, then I suggest you create some sort of UI that reports to the user that the images are loading. (To check wether the images are causing the lag, I suggest you have a look at DDMS are simply log with the LogCat)

I use the following code to save bitmaps to the memory:

The following will write to the memory:

public void writeBitmapToMemory(String filename, Bitmap bitmap) {
        FileOutputStream fos;
        // Use the compress method on the Bitmap object to write image to the OutputStream
        try {
            fos = game.openFileOutput(filename, Context.MODE_PRIVATE);
            // Writing the bitmap to the output stream
            bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);
            fos.close();
            // this.gameEngineLog.d(classTAG, "Bitmap successfully written: " + filename);
        } 
        catch (FileNotFoundException e) {
            e.printStackTrace();
            // this.gameEngineLog.d(classTAG, "Bitmap couldn't be written: " + filename);

        } 
        catch (IOException e) {
            e.printStackTrace();
            // this.gameEngineLog.d(classTAG, "Bitmap couldn't be written: " + filename);

        }

    }

this will read from the memory:

public Bitmap readBitmapFromMemory(String filename) {
        Bitmap defautBitmap = null;
        File filePath = game.getFileStreamPath(filename);
        FileInputStream fi;
        try {
            fi = new FileInputStream(filePath);
            defautBitmap = BitmapFactory.decodeStream(fi);
            // this.gameEngineLog.d(classTAG, "Bitmap successfully read: " + filename);
        } 
        catch (FileNotFoundException e) {
            e.printStackTrace();
            // this.gameEngineLog.d(classTAG, "Bitmap couldn't be opened: " + filename);
        }

        return defautBitmap;

    }
于 2012-07-25T16:06:46.520 回答