当快速滚动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;
}
最佳答案
我已经解决了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){
}
});
关于android - 当快速滚动Gridview时,项目消失。在快速滚动时图像尺寸也会改变,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31238913/