繁体   English   中英

Android如何创建堆栈类图像背景

[英]Android how to create the stack kind of image backgrounds

我正在开发一个应用程序,我需要创建相册并在GridView中显示它们。 现在我只是在没有任何背景的情况下显示它们,但我需要一个专辑封面的背景,以便它看起来像一堆照片。 背景是这样的:

在此输入图像描述

我尝试了这个,但它不起作用:

首先我创建了一个这样的背景:

<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>

然后我使用了一个图层列表来绘制带有旋转的堆栈:

<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个差异图像)。

我使用位图来创建堆栈视图并在imageview中显示它。 您可以基于此保存位图是资源然后将其添加到gridview中或者在getView中的gridview适配器中使用它我认为。

在此输入图像描述

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);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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