0

我在画廊中使用了这个 LoaderImageView。第一个我显示缩略图的网格。当用户单击缩略图图像时,我会获得该位置并传递给一个新活动,该活动显示“LoaderImageView”画廊,该画廊从互联网获取大图像,同时显示 ProgressBar。

我想要做的是当用户选择图像时,还应该有 b 自动调用下一个,上一个视图。实际上查看加载图像。

我正在尝试使用 OnItemSelectedListener();

有代码。但这不能正常工作。当我滚动前一个图像时,它会转到第一张图像。而且也没有按照我的逻辑工作。

class BigImageAdapter extends BaseAdapter {

    DisplayMetrics displayMatrics;
    HashMap<String, Bitmap> hasLargeBitmap;
    SharedPhotosData sharedPhotosData;
    Context mContext;

    public BigImageAdapter(Context contex, SharedPhotosData photoData) {

        mContext = contex;
        displayMatrics = new DisplayMetrics();
        hasLargeBitmap = new HashMap<String, Bitmap>();
        getWindowManager().getDefaultDisplay().getMetrics(displayMatrics);
        sharedPhotosData = photoData;
    }

    public void recycleAllBitmap() {
        try {
            int i = 0;
            Collection<Bitmap> temp = hasLargeBitmap.values();
            for (Bitmap bitmap : temp) {
                if (bitmap != null) {
                    if (bitmap.isRecycled() == false) {
                        bitmap.recycle();
                        i++;
                    }
                }
            }
            Log.e("Recycled", "No of images recycled"+i);

        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    public int getCount() {

        if (sharedPhotosData != null) {
            if (sharedPhotosData.photoData != null) {
                return sharedPhotosData.photoData.size();
            } else {
                Log.e(TAG, "sharedData.photoData is null");
            }
        } else {
            Log.e(TAG, "sharedData is null");
        }

        return 0;
    }

    public Object getItem(int position) {
        return position;
    }

    public long getItemId(int position) {

        return position;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        View rowView = null;
        try {
            MyData curData = null;
            curData = sharedPhotosData.photoData.get(position);
            if (convertView == null) {
                String imagePath = Environment.getExternalStorageDirectory().toString() + SMConstants.FILE_PATH_BASE
                        + SMConstants.S3Folders.PHOTO + curData.getLargeURLLocalPath() + "/" + SMConstants.FILE_NAME_PREFIX
                        + curData.getFileName();
                if (hasLargeBitmap.containsKey(imagePath) == false) {
                    rowView = new AsynImageView(hasLargeBitmap, PhotoGalleryActivity.this, curData);
                } else {
                    Bitmap image = hasLargeBitmap.get(imagePath);

                    ImageView mImageView = new ImageView(mContext);
                    mImageView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT,
                            Gravity.CENTER));
                    mImageView.setImageBitmap(image);
                    mImageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
                    mImageView.setAdjustViewBounds(true);
                    rowView = mImageView;
                }
                rowView.setLayoutParams(new Gallery.LayoutParams(android.view.ViewGroup.LayoutParams.FILL_PARENT,
                        android.view.ViewGroup.LayoutParams.FILL_PARENT));
            } else {
                rowView = convertView;
            }

        } catch (Exception e) {
            Log.e("Exception", "LargeSlideShow.GetView  Message = " + e);
            e.printStackTrace();
        } catch (Error e) {
            Log.e("Error", "LargeSlideShow.GetView Message = " + e);
            e.printStackTrace();
        }
        return rowView;
    }
}

@Override
public void onItemSelected(AdapterView<?> parent, View v, int position, long id) {
    try {

        if (position - 1 >= 0) {
            myGalleryForLargeImage.setSelection((position - 1));
        }
        if (position + 1 < size) {
            myGalleryForLargeImage.setSelection((position + 1));
        }
    } catch (Exception e) {
        Log.e(TAG, "Exception = " + e.toString());
        e.printStackTrace();
    }
}

@Override
public void onNothingSelected(AdapterView<?> arg0) {

}
4

1 回答 1

0

好的。我发现不是做“myGalleryForLargeImage.setSelection((position - 1));” 它必须完成。现在它尝试获取 View 并且当调用 getView() 方法时它会启动该图像请求。

@Override
public void onItemSelected(AdapterView<?> parent, View v, int position, long id) {
    try {

        if (position - 1 >= 0) {
            bigImageAdapter.getView(position-1, null, myGalleryForLargeImage);
        }
        if (position + 1 < size) {
            bigImageAdapter.getView(position+1, null, myGalleryForLargeImage);
        }
    } catch (Exception e) {
        Log.e(TAG, "Exception = " + e.toString());
        e.printStackTrace();
    }
}
于 2011-08-10T07:32:58.240 回答