滚动Gridview时项目消失得很快。此外,图像尺寸会在快速滚动时发生变化。 这是我的代码:
public View getView(final int position, View gridView, ViewGroup parent) {
final ViewHolder holder;
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (gridView == null) {
holder = new ViewHolder();
gridView = new View(context);
gridView = inflater.inflate( R.layout.view_initial_gallery, null);
holder.dirname = (TextView) gridView.findViewById(R.id.fname);
holder.dirimg = (ImageView) gridView.findViewById(R.id.folder);
holder.tick = (ImageView) gridView.findViewById(R.id.tick);
File file=folders.get(position).getFilelist().get(0);
holder.dirname.setText(folders.get(position).getFoldername());
Picasso.with(context)
.load(new File(file.getPath()))
.resize(300, 300)
.centerCrop()
.into(holder.dirimg);
gridView.setTag(holder);
}
else
{
holder = (ViewHolder)gridView.getTag();
}
return gridView;
}
答案 0 :(得分:1)
我已经修复了notifyDataSetChanged()的问题。希望它也适合你。
mGridView.setOnScrollListener(new AbsListView.OnScrollListener() {
// Boolean isScrollStop=false;
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
if (scrollState == AbsListView.OnScrollListener.SCROLL_STATE_IDLE) {
mAdapter.notifyDataSetChanged();
}
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount){
}
});
答案 1 :(得分:0)
我有同样的问题,除了我使用Glide而不是Picasso进行图像加载。我猜你的ImageView的尺寸设置为wrap_content
。尝试在dp&f; s中将高度和宽度设置为显式值,这对我有用。