我在布局中以编程方式添加多个ImageViews,除了ScrollView本身外,一切似乎都很好......它滚动得非常慢,并且在滚动时出现了很多卡顿。这可能是什么原因呢?
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/jobs_container"
>
</LinearLayout>
</ScrollView>
编辑: 我遵循了这个教程成功地创建了我的列表视图,但是在滚动过程中列表视图仍然会出现延迟。我从 Web 服务获取 ImageView 的源,因此我的行项目基本上如下:public class RowItem {
private String imageSrc;
private String title;
public RowItem(String src, String title)
{
this.imageSrc = src;
this.title = title;
}
public String getImageSrc()
{
return this.imageSrc;
}
public void setImageSrc(String src)
{
this.imageSrc = src;
}
public String getTitle()
{
return this.title;
}
public void setTitle(String title)
{
this.title = title;
}
}
我基本上是获取JSON对象列表,将它们转换为RowItem,然后使用以下代码生成ListView的行:
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
RowItem rowItem = getItem(position);
LayoutInflater mInflater = (LayoutInflater) context
.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
convertView = mInflater.inflate(R.layout.list_item, null);
holder = new ViewHolder();
holder.txtTitle = (TextView) convertView.findViewById(R.id.title);
holder.imageView = (ImageView) convertView.findViewById(R.id.icon);
convertView.setTag(holder);
} else
holder = (ViewHolder) convertView.getTag();
holder.txtTitle.setText(rowItem.getTitle());
String url = rowItem.getImageSrc();
url = url.replace("~", DOMAIN);
Picasso.with(context).load(url).into(holder.imageView);
return convertView;
}
它仍然非常卡顿...有任何想法吗?
更新: 我认为imageviews造成了慢滚动的问题,因为在图片下载和加载之前一切都很顺畅,但在图片加载后开始变慢,并且在每次滚动时,将显示的隐藏行重新加载图像。这可能是原因吗?