Android GridView从下到上加载图片问题

时间:2012-08-09 18:30:00

标签: android gridview asynchronous

我使用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

...

谢谢,

1 个答案:

答案 0 :(得分:0)

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

在gridview的xml中,输入:

android:stackFromBottom="false"