0

我正在使用 GridView 显示图像并以异步方式加载这些图像。一切正常,唯一的问题是图像从下到上加载到 GridView 中,而不是从上到下。真的无法理解如何解决这个问题。请在这个问题上帮助我。

EDIT1:GridView 适配器代码:

public class ImageThumbAdapter extends BaseAdapter {

        private Activity context;
        private ArrayList<HashMap<String, String>> mImageList;
        private ImageLoader mImageLoader;
        private int mItemHeight = 0;
        private int mNumColumns = 0;
        private GridView.LayoutParams mImageViewLayoutParams;

        public ImageThumbAdapter(Activity c,
                ArrayList<HashMap<String, String>> imageList) {
            context = c;
            mImageList = imageList;
            mImageLoader = new ImageLoader(context);
            mImageViewLayoutParams = new GridView.LayoutParams(
                    LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
        }

        public int getCount() {
            return mImageList.size();
        }

        public Object getItem(int position) {
            return mImageList.get(position);
        }

        public long getItemId(int position) {
            return position;
        }

        public void addImage(HashMap<String, String> image) {
            mImageList.add(image);
        }

        public View getView(int position, View convertView, ViewGroup parent) {


            // Now handle the main ImageView thumbnails
            ImageView imageView;

            if (convertView == null) { // if it's not recycled, instantiate and
                                        // initialize
                imageView = new ImageView(context);
                imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
                imageView.setLayoutParams(mImageViewLayoutParams);
            } 
            else { // Otherwise re-use the converted view
                imageView = (ImageView) convertView;
            }

            if (imageView.getLayoutParams().height != mItemHeight) {
                imageView.setLayoutParams(mImageViewLayoutParams);
            }

            String imageName = String.format(
                    "gallery_",
                    mImageList.get(position).get(TAG_THUMB_URL));

            imageView.setTag(imageName);
            mImageLoader.setDefualtStub(R.drawable.ic_thumbnail);

            mImageLoader.DisplayImage(
                    mImageList.get(position).get(TAG_THUMB_URL), context,
                    imageView, imageName, new ImageLoadingListener());

            return imageView;
        }

        ....

    }

Edit2:位置日志

08-10 23:16:23.132: I/System.out(785): Position: 0
08-10 23:16:23.142: I/System.out(785): Position: 0
08-10 23:16:23.142: I/System.out(785): Position: 1
08-10 23:16:23.152: I/System.out(785): Position: 2
08-10 23:16:23.152: I/System.out(785): Position: 3
08-10 23:16:23.152: I/System.out(785): Position: 4
08-10 23:16:23.162: I/System.out(785): Position: 5
08-10 23:16:23.162: I/System.out(785): Position: 6
08-10 23:16:23.162: I/System.out(785): Position: 7
08-10 23:16:23.172: I/System.out(785): Position: 8
08-10 23:16:23.172: I/System.out(785): Position: 9
08-10 23:16:23.172: I/System.out(785): Position: 10
08-10 23:16:23.182: I/System.out(785): Position: 11
08-10 23:16:23.182: I/System.out(785): Position: 12
08-10 23:16:23.192: I/System.out(785): Position: 13
08-10 23:16:23.192: I/System.out(785): Position: 14
08-10 23:16:23.192: I/System.out(785): Position: 15
08-10 23:16:23.312: D/dalvikvm(785): GC_EXPLICIT freed 434K, 20% free 9440K/11655K, paused 5ms+5ms
08-10 23:16:23.322: D/ImageLoader(785): gallery_http:%0%0s3.amazonaws.com%0DEV_ALC_USRDATA%013222763351652338265%0cms_Gallery%02x_1342687302114.143.121.36Apple-icon.gif.jpg Image doesn't exits in cache
08-10 23:16:23.322: D/ImageLoader(785): gallery_http:%0%0s3.amazonaws.com%0DEV_ALC_USRDATA%013222763351652338265%0cms_Gallery%02x_1342687302114.143.121.36Apple-icon.gif.jpg Downloading from server
08-10 23:16:23.902: D/dalvikvm(785): GC_EXPLICIT freed 98K, 19% free 9502K/11655K, paused 5ms+5ms
08-10 23:16:23.902: I/System.out(785): Position: 0
08-10 23:16:23.912: I/System.out(785): Position: 0
08-10 23:16:23.932: D/ImageLoader(785): igallery_http:%0%0s3.amazonaws.com%0DEV_ALC_USRDATA%013222763351652338265%0cms_Gallery%02x_1342687299114.143.121.3627.png.jpg Image doesn't exits in cache
08-10 23:16:23.952: D/ImageLoader(785): igallery_http:%0%0s3.amazonaws.com%0DEV_ALC_USRDATA%013222763351652338265%0cms_Gallery%02x_1342687299114.143.121.3627.png.jpg Downloading from server
08-10 23:16:25.202: D/dalvikvm(785): GC_EXPLICIT freed 110K, 18% free 9614K/11655K, paused 4ms+6ms
08-10 23:16:25.212: I/System.out(785): Position: 0
08-10 23:16:25.222: I/System.out(785): Position: 0
08-10 23:16:25.242: D/ImageLoader(785): igallery_http:%0%0s3.amazonaws.com%0DEV_ALC_USRDATA%013222763351652338265%0cms_Gallery%02x_1342572563101.98.165.177bleyendall.png.jpg Image doesn't exits in cache
08-10 23:16:25.262: D/ImageLoader(785): igallery_http:%0%0s3.amazonaws.com%0DEV_ALC_USRDATA%013222763351652338265%0cms_Gallery%02x_1342572563101.98.165.177bleyendall.png.jpg Downloading from server
08-10 23:16:26.122: D/dalvikvm(785): GC_EXPLICIT freed 89K, 17% free 9691K/11655K, paused 4ms+5ms
08-10 23:16:26.122: I/System.out(785): Position: 0
08-10 23:16:26.132: I/System.out(785): Position: 0

...

谢谢,

4

1 回答 1

0

在我发现 gridview 的 stackFromBottom 属性之前,我遇到了同样的问题。

在 gridview 的 xml 中,输入:

android:stackFromBottom="false"
于 2013-11-22T18:11:13.750 回答