getView方法在位置0多次调用 因此,加载此活动需要更多时间,并且当getView调用时,每次都在Imageview中设置Bitamp
我也尝试将列表视图高度设置为fillparent但不解决我的问题
Xml文件中的ListView
<RelativeLayout android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ListView android:id="@+id/lv_order_list"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"
android:listSelector="@android:color/transparent" >
</ListView>
</RelativeLayout>
Listview中的getView方法
@Override
public View getView(final int position, View convertView,
ViewGroup parent) {
myView = convertView;
System.out.println("get view" + position);
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
myView = inflater.inflate(layoutResourceId, parent, false);
ImageView img_order = (ImageView) myView
.findViewById(R.id.img_order);
TextView title_of_ink = (TextView) myView
.findViewById(R.id.title_of_ink);
title_of_ink.setText("Text");
picasso.load("url").noFade().into(img_order);
return myView;
}
答案 0 :(得分:3)
getView
,这就是ListView
的工作方式。
为了提高性能,您可以使用两种技术:
1)查看回收 - 你做错了
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = mInflater.inflate(R.layout.your_layout, null);
}
TextView text = (TextView) convertView.findViewById(R.id.text);
text.setText("Position " + position);
return convertView;
}
2)使用ViewHolder模式
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.your_layout, null);
holder = new ViewHolder();
holder.text = (TextView) convertView.findViewById(R.id.text);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.text.setText("Position " + position);
return convertView;
}
private static class ViewHolder {
public TextView text;
}
3)图像的异步加载
它是大写字母P,你错过了Context
参数
Picasso.with(context).load("http://i.imgur.com/DvpvklR.png").into(imageView);
从lucasr.org借来的代码。