简体   繁体   中英

Android how to create the stack kind of image backgrounds

I am developing an App where i need to create Albums and display them in a GridView. Now i am just displaying them without any background but i need a background for the Album cover so that it looks like a pile of photos. Background something like this:

在此输入图像描述

I tried out this but not it's working:

first i created a single background like this:

<shape xmlns:android="http://schemas.android.com/apk/res/android" >

    <solid android:color="#FFFFFF" />

    <stroke
        android:width="1dp"
        android:color="#000000" />

    <padding
        android:bottom="1dp"
        android:left="1dp"
        android:right="1dp"
        android:top="1dp" />

</shape>

And then i used a layer-list to draw the stack with rotation:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

    <rotate
        android:drawable="@drawable/thumb_bg"
        android:fromDegrees="90"
        android:pivotX="50%"
        android:pivotY="50%"
        android:toDegrees="100" />
    <rotate
        android:drawable="@drawable/thumb_bg"
        android:fromDegrees="90"
        android:pivotX="50%"
        android:pivotY="50%"
        android:toDegrees="110" />
    <rotate
        android:drawable="@drawable/thumb_bg"
        android:fromDegrees="90"
        android:pivotX="50%"
        android:pivotY="50%"
        android:toDegrees="120" />

</layer-list>

将您的相册拇指放在虚拟图像上(其中包含2或3个差异图像)。

I use bitmap to create the stack view and show it in a imageview. You can based on this to save the bitmap is resource then add it in the gridview or use it in gridview adapter in getView I think.

在此输入图像描述

Bitmap m1c = BitmapFactory.decodeResource(getResources(), R.drawable.cat_13);
Bitmap m2c = BitmapFactory.decodeResource(getResources(), R.drawable.cat_13);


int w = m1c.getWidth();
int h = m1c.getHeight();

Matrix mtx = new Matrix();
mtx.postRotate(4);
Bitmap rotatedBMP = Bitmap.createBitmap(m1c, 0, 0, w, h, mtx, true);

Matrix mtx2 = new Matrix();
mtx2.postRotate(-4);

Bitmap rotatedBMP2 = Bitmap.createBitmap(m1c, 0, 0, w, h, mtx2, true);


Canvas comboImage = new Canvas(rotatedBMP);
comboImage.drawBitmap(rotatedBMP2, -10 , -10 , null);
comboImage.drawBitmap(m2c, 10 , 10 , null);

ImageView image = (ImageView) findViewById(R.id.imageView1);
image.setImageBitmap(rotatedBMP);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM