打开图像对话框/ GridView的速度很慢 [英] Open image dialog/GridView is very slow

查看:191
本文介绍了打开图像对话框/ GridView的速度很慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有什么

我在一个活动的打开的图像对话框。这种对话框中的只显示文件夹和兼容的影像。为此,我有一个gridview,我充满了包含图像和文本行的层。

的文本是该文件的名称和图像为图像的preVIEW

我的问题

该对话框行之有效如果我看到该文件夹​​不有大量的图像。我工作的一个SII,当我尝试打开相册(8Mpx照片),它甚至一个新行redrawed每次跟我的code非常缓慢。

我的code

我认为主要问题在于创建preVIEW图像的,因为如果我删除了这部分一切工作正常。对于图像,我有:

  @覆盖
公共查看getView(INT位置,查看convertView,父母的ViewGroup){
   查看网格;   如果(convertView == NULL){
       格=新景(mContext);
       LayoutInflater吹气= getLayoutInflater();
       格= inflater.inflate(R.layout.row,父母,假);
   }其他{
       格=(查看)convertView;
   }   ImageView的图标=(ImageView的)grid.findViewById(R.id.file_image);
   TextView的标签=(TextView中)grid.findViewById(R.id.file_text);
   label.setText(item.get(位置));
    如果(item.get(位置).equals(/)){
        icon.setImageResource(R.drawable.folderupup);
    }否则如果(item.get(位置).endsWith(../)){
        icon.setImageResource(R.drawable.folderup);
    }否则如果(item.get(位置).endsWith(/)){
        icon.setImageResource(R.drawable.folder);
    }其他{
        位图B = BitmapFactory.de codeFILE(path.get(位置));
        位图B2 = Bitmap.createScaledBitmap(B,55,55,FALSE);
        icon.setImageBitmap(B2);
    }   返回网格;
  }
 }


解决方案

最后,我都认为Android页面做说没有高速缓存做任何事情。现在列表加载速度快。也许我可以添加内存缓存文汇指出,但它是如此之快,它并没有为我的目的无关紧要。

该试验已经在SII已经完成含有大约400与8Mpx文件夹

What I have

I have an "open image dialog" in an activity. This "dialog" only shows folders and compatible images. For this I have a layer with a gridview that I fill with rows that contains an image and a text.

The text is for the name of the file and the image is for a preview of the image.

My problem

The dialog works well if the folder that I'm seeing doesn't have lots of images. I'm working on a SII and when I try to open the camera album (photos of 8Mpx) it goes very slow with my code, even each time a new row is redrawed.

My code

I think the main problem resides in the creation of the preview images because if I delete this part all works fine. For the images, I have:

  @Override
public View getView(int position, View convertView, ViewGroup parent) {
   View grid;

   if(convertView==null){
       grid = new View(mContext);
       LayoutInflater inflater=getLayoutInflater();
       grid=inflater.inflate(R.layout.row, parent, false);
   }else{
       grid = (View)convertView;
   }

   ImageView icon = (ImageView)grid.findViewById(R.id.file_image);
   TextView label = (TextView)grid.findViewById(R.id.file_text);
   label.setText(item.get(position));
    if (item.get(position).equals("/")){
        icon.setImageResource(R.drawable.folderupup);
    }else if (item.get(position).endsWith("../")) {
        icon.setImageResource(R.drawable.folderup);
    }else if (item.get(position).endsWith("/")) {    
        icon.setImageResource(R.drawable.folder);
    }else{
        Bitmap b = BitmapFactory.decodeFile(path.get(position));
        Bitmap b2 = Bitmap.createScaledBitmap(b, 55, 55, false);
        icon.setImageBitmap(b2);
    }

   return grid;
  }
 }

解决方案

Finally I did all that the Android page said without doing anything for the cache. Now the list loads fast. Maybe I could add a memory cache as Wenhui pointed but it is so fast that it doesn't matter for my purposes.

The test has been done on a SII with a folder containing around 400 with 8Mpx

这篇关于打开图像对话框/ GridView的速度很慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆