问题描述:
我正在创建一个带缩略图的可滚动文章列表,其中缩略图是通过我的SQLite数据库填充的。总体而言,它“工作”得很好,只是速度有点慢:
图片加载非常缓慢... 我以为使用 “Universal Image Loader”会在设备上缓存图像,并且这样会使它们似乎只是在视图中滚动,如果您已经查看过它们(或者至少接近于此)。但是-当您向上/向下拖动时,没有任何图像,然后3-5秒钟后,图像开始弹出(就像它们正在重新下载一样)
我正在动态更改缩略图框的可见性,但那完美无缺-它们似乎不会改变-它们只是滚动进入或退出视图,没有闪烁或任何东西。 (但是几秒钟后,图像才会出现)。
我通过移除滚动时的php脚本进行了测试...当我滚回到先前的位置时,图像不会显示-让我认为它每次都从我的PHP脚本加载。
但是根据文档:“UsingFreqLimitedMemoryCache(当缓存大小超过限制时,删除最不常用的位图)-默认使用”
详细信息:
在我的ArticleEntryAdapter.js
中,我有:
@Override
public View getView(final int position, final View convertView, final ViewGroup parent) {
// We need to get the best view (re-used if possible) and then
// retrieve its corresponding ViewHolder, which optimizes lookup efficiency
final View view = getWorkingView(convertView);
final ViewHolder viewHolder = getViewHolder(view);
final Article article = getItem(position);
// Set the title
viewHolder.titleView.setText(article.title);
//Set the subtitle (subhead) or description
if(article.subtitle != null)
{
viewHolder.subTitleView.setText(article.subtitle);
}
else if(article.description != null)
{
viewHolder.subTitleView.setText(article.description);
}
ImageLoader imageLoader = ImageLoader.getInstance();
imageLoader.displayImage("", viewHolder.thumbView); //clears previous one
if(article.filepath != null && article.filepath.length() != 0) {
imageLoader.displayImage(
"http://img.sltdb.com/processes/resize.php?image=" + article.filepath + "&size=100&quality=70",
viewHolder.thumbView
);
viewHolder.thumbView.setVisibility(View.VISIBLE);
} else {
viewHolder.thumbView.setVisibility(View.GONE);
}
return view;
}
就图像不正确而言——虽然不经常发生,但有时在滚动时,我会看到两张相同的图像,当我查看文章时,它们根本没有关联(即没有机会实际拥有相同的图像)。因此,我将其向上或向下滚动,再次查看时,这张不正确的图像就变成了正确的图像。
提示:我是Java / Android的新手--您可能已经注意到了。
更多代码请参阅评论请求:
private View getWorkingView(final View convertView) {
// The workingView is basically just the convertView re-used if possible
// or inflated new if not possible
View workingView = null;
if(null == convertView) {
final Context context = getContext();
final LayoutInflater inflater = (LayoutInflater)context.getSystemService
(Context.LAYOUT_INFLATER_SERVICE);
workingView = inflater.inflate(articleItemLayoutResource, null);
} else {
workingView = convertView;
}
return workingView;
}
更新: 我的清单文件包含:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
但是我找到的缓存文件夹是完全空的:
mnt
-sdcard
-Android
-data
-com.mysite.news
-cache
-uil-images
getWorkingView(convertView);
是什么? - Sherif elKhatib