我有ListView,包括具有不同高度的項目。當我向上滾動時,它不光滑,並且會產生跳躍效果。所有項目都有wrap_content高度。我怎樣才能平滑地向上滾動?向上滾動ListView與不同項目的高度
這裏的適配器代碼:
public class EventFeedAdapter extends ArrayAdapter<Post> {
public EventFeedAdapter(Context context, List<Post> items) {
super(context, R.layout.item_event_feed, items);
}
@Override
public View getView(int position, View convertView, ViewGroup arg2) {
if (convertView == null) {
convertView = View.inflate(getContext(), R.layout.item_event_feed,
null);
ViewHolder vh = new ViewHolder();
vh.avatar = (ImageView) convertView.findViewById(R.id.avatar);
vh.photo = (ImageView) convertView.findViewById(R.id.photo);
vh.textName = (TextView) convertView.findViewById(R.id.textName);
vh.textTime = (TextView) convertView.findViewById(R.id.textTime);
vh.progress = (ProgressBar) convertView.findViewById(R.id.progress);
vh.buttonLike = (ImageView) convertView
.findViewById(R.id.buttonLike);
vh.buttonMore = (ImageView) convertView
.findViewById(R.id.buttonMore);
vh.textLikes = (TextView) convertView.findViewById(R.id.textLikes);
convertView.setTag(vh);
}
final ViewHolder holder = (ViewHolder) convertView.getTag();
Post post = getItem(position);
String name = post.isFake() ? UserModel.get().getUser().getName()
: post.getDisplayName();
String avatar = post.isFake() ? UserModel.get().getUser()
.getPictureUrl() : post.getProfileThumb();
String mediaUrl = post.isFake() ? String.format("file://%s",
post.getLocalMediaUri()) : post.getMediaFeed().getUrl();
ImageLoader.getInstance().displayImage(mediaUrl, holder.photo,
new ImageLoadingListener() {
@Override
public void onLoadingStarted(String imageUri, View view) {
holder.progress.setVisibility(View.VISIBLE);
}
@Override
public void onLoadingFailed(String imageUri, View view,
FailReason failReason) {
holder.progress.setVisibility(View.GONE);
}
@Override
public void onLoadingComplete(String imageUri, View view,
Bitmap loadedImage) {
holder.progress.setVisibility(View.GONE);
}
@Override
public void onLoadingCancelled(String imageUri, View view) {
holder.progress.setVisibility(View.GONE);
}
});
ImageLoader.getInstance().displayImage(avatar, holder.avatar);
holder.textName.setText(name);
Date date = post.isFake() ? post.getLocalDate() : post.getCreatedAt();
holder.textTime.setText(DateUtils.getFormattedDate(getContext(), date));
holder.buttonLike
.setImageResource(post.isLocalLiked() ? R.drawable.icon_heart_filled
: R.drawable.icon_heart);
if (post.isLocalLiked() && post.getLocalLikesCount() == 1)
holder.textLikes.setText(R.string.you_like_this);
else if (post.getLocalLikesCount() > 0)
holder.textLikes.setText(String.format(
getContext().getString(R.string.likes),
post.getLocalLikesCount()));
else
holder.textLikes.setText("");
holder.buttonLike.setTag(post);
holder.buttonMore.setTag(post);
return convertView;
}
class ViewHolder {
ImageView photo;
ImageView avatar;
ImageView buttonLike;
ImageView buttonMore;
TextView textName;
TextView textTime;
ProgressBar progress;
TextView textLikes;
}
}
如果我使用固定高度的項目滾動精品工程。
發表您的ListView BaseAdapter代碼在這裏.. –