如何优化的Android的ListView? [英] How to optimize Android ListView?
问题描述
我已经定制了自己的ListAdapter和我展现3种不同的图像(项目)为1行。 它完美(根据它的功能)。 然而,这不是能够顺利地滚动的ListView。
I have customized my ListAdapter and i show 3 different Images (items) in 1 row. It works perfectly (according to it's function). However, it's not possible to scroll the ListView smoothly.
我使用了setBackgroundImage上ImageViews我用一个HashMap来高速缓存RESOURCEID;所以我没有用
I am using setBackgroundImage on ImageViews and i use an HashMap to cache resourceId; so i don't have to use
渣油=的getContext()getResources()则getIdentifier(resName,绘制,appContext.getPackageName());
连连。
我觉得我失去了一些东西作为ListView控件不滚动很好。另外,如果我尝试在平板电脑在我的code自动在一排罢了超过3项,平板电脑的列表视图几乎unscrollable。
I think i am missing something as the ListView is not scrolling well. Also if i try it on a tablet where my code automatically fills more than 3 items on a row, tablet's listview is almost unscrollable.
我究竟做错了什么?
更新:
我在我的标志(国家的国旗)编程创建的ListView活动的onCreate方法:
I create ListView programmatically in my Flags (country flags) Activity's onCreate method:
根=(ViewGroup中)this.findViewById(R.id.root);
root=(ViewGroup)this.findViewById(R.id.root);
listView=new ListView(this);
listView.setLayoutParams(new LayoutParams(
LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT));
/*
ArrayList<Country> dataList=new ArrayList<Country>(){{
add(new Country("jp"));
add(new Country("de"));
add(new Country("it"));
}};*/
CountryListAdapter countryListAdapter=new CountryListAdapter(this);
countryListAdapter.setDataSource(allCountries);
listView.setAdapter(regionListAdapter);
listView.setBackgroundColor(0xFF000000);
listView.setDividerHeight(0);
root.addView(listView);
推荐答案
学习,学习和研究; - )
Study, study and study ;-)
和我的提示是使用 ViewHolder 的模式,为众多项目的的布局相同的(哪怕是simpliest之一,如单的TextView)
And my tip is to use ViewHolder pattern, for large number of item's of same layout (even if it is the simpliest one, such as single TextView)
- 在谷歌I / O 2009 - ...让您的Android UI快速高效 http://www.youtube.com /手表?ν= N6YdwzAvwOA
- 在谷歌I / O 2010 - ListView中的世界 http://www.youtube.com/watch?v=wDBM6wVEO70
- <一个href="http://www.technotalkative.com/category/android/listview/">http://www.technotalkative.com/category/android/listview/
- 查看持有者 - 好习惯
- 为什么用ViewHolder pattren工作?
- <一个href="http://stackoverflow.com/questions/12368302/is-it-crucial-for-performance-to-have-viewholder-as-static-in-a-viewholder-patte">Is它的性能是至关重要的有ViewHolder静态的ViewHolder模式?
- Google I/O 2009 - ...Make your Android UI Fast and Efficient http://www.youtube.com/watch?v=N6YdwzAvwOA
- Google I/O 2010 - The world of ListView http://www.youtube.com/watch?v=wDBM6wVEO70
- http://www.technotalkative.com/category/android/listview/
- View holder - good practice
- why does the ViewHolder pattren work?
- Is it crucial for performance to have ViewHolder as static in a ViewHolder pattern?
和也是这个 ViewHolder
实施示例/库
And also this ViewHolder
implementation example/library
- <一个href="https://github.com/rtyley/android-viewholder-listviews">https://github.com/rtyley/android-viewholder-listviews (阿帕奇2.0)
- https://github.com/rtyley/android-viewholder-listviews (Apache 2.0)
另外,如果你在你的ListView项目布局中使用的图像,你可以使用一些库异步下载图像,如:
Also if you do use images in your ListView items layout, you can use some libraries to download images asynchronously, such as:
- <一个href="https://github.com/nostra13/Android-Universal-Image-Loader">https://github.com/nostra13/Android-Universal-Image-Loader
- <一个href="http://stackoverflow.com/questions/541966/how-do-i-do-a-lazy-load-of-images-in-listview/3068012#3068012">How我该怎么做图像的延迟加载ListView中
- <一个href="http://android-developers.blogspot.cz/2010/07/multithreading-for-performance.html">http://android-developers.blogspot.cz/2010/07/multithreading-for-performance.html
- https://github.com/nostra13/Android-Universal-Image-Loader
- How do I do a lazy load of images in ListView
- http://android-developers.blogspot.cz/2010/07/multithreading-for-performance.html
这篇关于如何优化的Android的ListView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!