怎么样能在一个文件夹上显示文件夹里面的图片内容,就像windows装图片的文件夹那样,在文件夹上显示4个缩略图

解决方案 »

  1.   

    呵呵,我正好看过android1.5自带的图片浏览器,里边有一个方法正好是做这个事情的:
     private Bitmap makeMiniThumbBitmap(int width, int height, ImageManager.IImageList images) {
            int count = images.getCount();
            // We draw three different version of the folder image depending on the number of images in the folder.
            //    For a single image, that image draws over the whole folder.
            //    For two or three images, we draw the two most recent photos.
            //    For four or more images, we draw four photos.
            final int padding = 4;
            int imageWidth = width;
            int imageHeight = height;
            int offsetWidth = 0;
            int offsetHeight = 0;        imageWidth = (imageWidth - padding) / 2;     // 2 here because we show two images
            imageHeight = (imageHeight - padding) / 2;   // per row and column        final Paint  p = new Paint();
            final Bitmap b = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
            final Canvas c = new Canvas(b);        final Matrix m = new Matrix();        // draw the whole canvas as transparent
            p.setColor(0x00000000);
            c.drawPaint(p);        // draw the mask normally
            p.setColor(0xFFFFFFFF);
            mFrameGalleryMask.setBounds(0, 0, width, height);
            mFrameGalleryMask.draw(c);        Paint pdpaint = new Paint();
            pdpaint.setXfermode(new android.graphics.PorterDuffXfermode(
                                        android.graphics.PorterDuff.Mode.SRC_IN));        pdpaint.setStyle(Paint.Style.FILL);
            c.drawRect(0, 0, width, height, pdpaint);        for (int i = 0; i < 4; i++) {
                if (mPausing) {
                    return null;
                }            Bitmap temp = null;
                ImageManager.IImage image = i < count ? images.getImageAt(i) : null;            if (image != null) {
                    temp = image.miniThumbBitmap();
                }            if (temp != null) {
                    if (ImageManager.isVideo(image)) {
                        Bitmap newMap = temp.copy(temp.getConfig(), true);
                        Canvas overlayCanvas = new Canvas(newMap);
                        int overlayWidth = mVideoOverlay.getIntrinsicWidth();
                        int overlayHeight = mVideoOverlay.getIntrinsicHeight();
                        int left = (newMap.getWidth() - overlayWidth) / 2;
                        int top = (newMap.getHeight() - overlayHeight) / 2;
                        Rect newBounds = new Rect(left, top, left + overlayWidth, top + overlayHeight);
                        mVideoOverlay.setBounds(newBounds);
                        mVideoOverlay.draw(overlayCanvas);
                        temp.recycle();
                        temp = newMap;
                    }                Bitmap temp2 = ImageLoader.transform(m, temp, imageWidth, imageHeight, true);
                    if (temp2 != temp)
                        temp.recycle();
                    temp = temp2;
                }            Bitmap thumb = Bitmap.createBitmap(imageWidth, imageHeight, Bitmap.Config.ARGB_8888);
                Canvas tempCanvas = new Canvas(thumb);
                if (temp != null)
                    tempCanvas.drawBitmap(temp, new Matrix(), new Paint());
                mCellOutline.setBounds(0, 0, imageWidth, imageHeight);
                mCellOutline.draw(tempCanvas);            placeImage(thumb, c, pdpaint, imageWidth, padding, imageHeight, padding, offsetWidth, offsetHeight, i);            thumb.recycle();            if (temp != null)
                    temp.recycle();
            }        return b;
        }
      

  2.   

    其实就是得到文件夹里边图片缩略图,然后用canvas画在文件夹上。不过你要计算画的位置和间隔等信息。
      

  3.   

    另外,这个方法并不是拿来就能用的,这只是其中的代码片段,如果你有源码,你可以找camera应用下的GalleryPicker类
      

  4.   

    谢谢你,请问你是怎么import android.provider.DrmStore和import android.media.MediaMetadataRetriever的啊?