首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在ListView中具有图像的低FPS

在ListView中具有图像的低FPS
EN

Stack Overflow用户
提问于 2015-11-12 17:46:30
回答 2查看 187关注 0票数 1

我正在为我的大学餐厅制作一个应用程序。

我有一个ScrollView,里面有两个ListView (一个是第一个菜,另一个是第二个菜)。

我用下面的代码创建ListView:

代码语言:javascript
复制
ListView lista = (ListView)view.findViewById(R.id.listaprimero); //first dishes
ArrayList<Plato> arraydir = new ArrayList<Plato>(); //array for first dishes

ListView listaS = (ListView)view.findViewById(R.id.listasegundo); //second dishes
ArrayList<Plato> arraydirS = new ArrayList<Plato>(); //array for second dishes

Plato plato; //Object "dish"

//Now for each dish that I want to add, I use the object "Plato" 
//to create a dish with its photo and its name.
//Then I add it to the ArrayList

plato = new Plato(getResources().getDrawable(R.drawable.macarrones), "Macarrones", "Amenizador");
arraydir.add(plato);
plato = new Plato(getResources().getDrawable(R.drawable.arroz), "Arroz tres delicias", "CEO");
arraydir.add(plato);
plato = new Plato(getResources().getDrawable(R.drawable.ternera), "Ternera", "Amenizador");
arraydir.add(plato);
plato = new Plato(getResources().getDrawable(R.drawable.pollo), "Filetitos de pollo", "Directora RRHH");
arraydirS.add(plato);
plato = new Plato(getResources().getDrawable(R.drawable.merluza), "Merluza al horno", "Directora RRHH");
arraydirS.add(plato);

// I create the Adapter for the dishes
AdapterPlatos adapter = new AdapterPlatos(getActivity(), arraydir);
AdapterPlatos adapterS = new AdapterPlatos(getActivity(), arraydirS);

// Set it
lista.setAdapter(adapter);
listaS.setAdapter(adapterS); 

现在,当我运行这个应用程序时,我的FPS非常低,而Android控制台每次都说:“跳过32帧!应用程序可能在其主线程上做了太多的工作。”

但当我制作这样的菜肴时:

代码语言:javascript
复制
plato = new Plato(getResources().getDrawable(R.drawable.macarrones), "Dish 1", "Amenizador");
    arraydir.add(plato);
plato = new Plato(getResources().getDrawable(R.drawable.macarrones), "Dish 2", "Amenizador");
    arraydir.add(plato);
plato = new Plato(getResources().getDrawable(R.drawable.macarrones), "Dish 3", "Amenizador");
    arraydir.add(plato);
plato = new Plato(getResources().getDrawable(R.drawable.macarrones), "Dish 4", "Amenizador");
    arraydirS.add(plato);
...

使用相同的照片,没有问题发生。

PD:照片的大小在70到200 of之间,而不是沉重的文件。

为什么?

谢谢大家。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-11-12 17:52:03

解码并加载可绘制(位图)到内存中仍然需要时间来显示。

如果您的Plato对象只保留可绘制对象的资源id,而不保留可绘图本身,则会更好。这将占用更少的内存。然后,在适配器getView()中,可以使用类似于滑行的东西将该资源加载到ImageView中。

代码语言:javascript
复制
Glide.with(context).load(R.drawable.macarrones).into(imageView);
票数 1
EN

Stack Overflow用户

发布于 2015-11-12 18:06:19

确保图像对于容器的大小是正确的。动态调整图像的大小在计算上花费很大,并且导致应用程序性能下降,特别是在ListViews方面。

如果从服务器获取图像,或者支持不同的显示大小,则可以考虑先使用后台线程来调整它们的大小,然后使用调整大小的线程而不是原始文件(在分配给视图时需要动态调整大小)。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33677936

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档