【发布时间】:2013-04-24 19:53:27
【问题描述】:
我已经自定义了我的 ListAdapter,并在 1 行中显示了 3 个不同的图像(项目)。 它完美地工作(根据它的功能)。 但是,无法平滑滚动 ListView。
我在 ImageViews 上使用 setBackgroundImage,我使用 HashMap 来缓存 resourceId;所以我不必使用
resId=getContext().getResources().getIdentifier(resName, "drawable",appContext.getPackageName());
一次又一次。
我想我错过了一些东西,因为 ListView 不能很好地滚动。另外,如果我在平板电脑上尝试,我的代码会自动在一行中填充 3 个以上的项目,平板电脑的列表视图几乎无法滚动。
我在这里做错了什么?
更新:
我在我的 Flags(国家标志)Activity 的 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);
【问题讨论】:
-
“不太好”和“顺利”是什么意思?
-
至少向我们展示您为 ListView 项创建视图的代码。
-
使用 Traceview 准确确定您将时间花在哪里。此外,请
StrictMode就主应用程序线程上的明显问题向您大喊大叫。 -
为了更好的平滑滚动使用ViewHolder和后台线程。您可以查看this 一个。