1

我有一个 Gridview 可以正确加载数据并且很流畅。我遇到的问题是,当用户以任何速度滚动 Gridview 时,他们可以看到 UI 中的图像发生变化。图像最终会出现在正确的位置,但对用户来说并不是很美观。我想知道我做错了什么以及我能做些什么来获得一个干净的卷轴。需要注意的是,我使用的是通用图像加载器和光标加载器。我的适配器代码发布在下面。

class VideoAdapter extends CursorAdapter {
Context context; 
private static final String TAG = "Checking Database";
ImageLoaderConfiguration config;
public VideoAdapter(Context context, Cursor c, int flags) {
    super(context, c, flags);
    this.context = context;

    config = new ImageLoaderConfiguration.Builder(context)
    .memoryCache(new LruMemoryCache(2 * 1024 * 1024))
    .imageDownloader(new BaseImageDownloader(context))
    .build();

    DisplayImageOptions defaultOptions =
            new DisplayImageOptions.Builder()
                    .cacheOnDisc()
                    .imageScaleType(ImageScaleType.EXACTLY) 
                    .bitmapConfig(Bitmap.Config.RGB_565)
                    .build();

    ImageLoader.getInstance().init(config);
    Log.i(TAG, "at thconstructore end of the the ");
}

@Override
public void bindView(View view, Context context, Cursor cursor) {
    ViewHolder holder = (ViewHolder) view.getTag();
    int videoid = cursor.getColumnIndex(GridviewData.ROWID);
    int videopath = cursor.getColumnIndex(GridviewData.VIDEOFILEPATH);
    String rowid = cursor.getString(videoid);
    String filepath = cursor.getString(videopath);
            //This background thread downloads/looks for the bitmap and sets it to the  view
    BitmapDownloader bitdl = new BitmapDownloader(rowid, filepath,    holder.imageview);
    bitdl.execute();
}

@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
    LayoutInflater inflater = (LayoutInflater) context
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View eachgrid = inflater.inflate(R.layout.eachgrid, parent, false);
    ViewHolder holder = new ViewHolder();
    holder.imageview = (ImageView) eachgrid
            .findViewById(R.id.Imageview1);
    eachgrid.setTag(holder);
    return eachgrid;        
}

谢谢你的帮助。

4

0 回答 0