【发布时间】:2012-07-11 13:00:57
【问题描述】:
问题描述: 我正在创建一个可滚动的文章列表,其中包含由我的 SQLite 数据库填充的缩略图。一般来说,它是“工作”的,除了速度很慢:
图像加载非常缓慢...我认为使用“Universal Image Loader”将图像缓存在设备上,如果您已经查看过它们(或至少接近)。但是 - 当你向上/向下拖动时,没有图像,然后 3-5 秒后,图像开始弹出(好像它正在重新下载它们)
我正在动态更改缩略图框的可见性,但效果很好 - 它们似乎没有改变 - 它们只是滚动到视图中,没有闪烁或任何东西。 (但随后图像不会再出现几秒钟)。
我已经通过在滚动后删除我的 php 脚本进行了测试...当我滚动回上一个位置时,图像不显示 - 让我假设它每次都从我的 PHP 脚本加载。
但根据the docs:“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;
}
至于图像不正确 - 这并不常见,但有时在滚动时,我会看到 2 个相同的图像,当我查看文章时,它们根本不相关(即没有机会实际上有相同的图像)所以 - 我滚动离开它,然后返回,它不再是不正确的图像。
注意:我是 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 - 已添加
标签: java android image listview