我已经定制了我的ListAdapter,并且我在1行中显示了3个不同的图像(项目)。 它完美的工作(根据它的功能)。 但是,无法顺利滚动ListView。如何优化Android ListView?
我在ImageViews上使用setBackgroundImage,我使用HashMap来缓存resourceId;所以我不必反复使用
resId=getContext().getResources().getIdentifier(resName, "drawable",appContext.getPackageName());
。
我想我错过了一些ListView不能很好的滚动。另外,如果我在平板电脑上尝试它,我的代码会自动填充超过3行的项目,平板电脑的列表视图几乎不可滚动。
我在这里做错了什么?
UPDATE:
我编程我的标志(国家的国旗)活动的onCreate方法创建的ListView:
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);
“不好”和“顺利”是什么意思? – 2013-04-24 19:56:28
向我们展示至少为您创建ListView项目视图的代码。 – SimonSays 2013-04-24 19:57:40
使用Traceview精确确定你在哪里花费时间。另外,激活'StrictMode'来对你的主应用程序线程显而易见的问题大喊大叫。 – CommonsWare 2013-04-24 20:09:21