android 中的图库相册封面效果

Image gallery album cover effect in android

我想在android

中制作类似附件图像的效果

有人可以帮忙吗?

您可以使用 this library 来解决您的问题:

代码示例可能如下所示:

mageView mImageView;
PhotoViewAttacher mAttacher;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // Any implementation of ImageView can be used!
    mImageView = (ImageView) findViewById(R.id.iv_photo);

    // Set the Drawable displayed
    Drawable bitmap = getResources().getDrawable(R.drawable.wallpaper);
    mImageView.setImageDrawable(bitmap);

    // Attach a PhotoViewAttacher, which takes care of all of the zooming functionality.
    mAttacher = new PhotoViewAttacher(mImageView);
}


// If you later call mImageView.setImageDrawable/setImageBitmap/setImageResource/etc then you just need to call
attacher.update();

否则,您可以从 Android 文档中阅读 the documentation 关于过渡和动画的内容。甚至还有很多例子。

我是用下面的方法做的:)

public Bitmap getImageAlbumCover (Bitmap sourceBitmap) {

        Bitmap resultBitmap = Bitmap.createBitmap(sourceBitmap, 0, 0,
                sourceBitmap.getWidth()-1, sourceBitmap.getHeight()-1);
        int padding = 15;
        int width = resultBitmap.getWidth();
        int height = resultBitmap.getHeight();

        Canvas canvas = new Canvas(resultBitmap);
        Rect srcRect = new Rect(0, 0, width, height);
        Rect desrect1 = new Rect((-1 * 1 * padding), (3 * padding) , width + (-1 * 1 * padding), height + (-1 * 3 * padding));
        Rect desrect2 = new Rect((-1 * 2 * padding), (2 * padding) , width + (-1 * 2 * padding), height + (-1 * 2 * padding));
        Rect desrect3 = new Rect((-1 * 3 * padding), (1 * padding) , width + (-1 * 3 * padding), height + (-1 * 1 * padding));



        Paint paint = new Paint();
        paint.setColor(Color.WHITE);
        canvas.drawRect(0, 0, width, height, paint);

        paint.setAlpha(64);

        canvas.drawBitmap(sourceBitmap, srcRect, desrect1, paint);

        paint.setAlpha(128);

        canvas.drawBitmap(sourceBitmap, srcRect, desrect2, paint);

        paint.setAlpha(255);

        canvas.drawBitmap(sourceBitmap, srcRect, desrect3, paint);

        return resultBitmap;
    }