【问题标题】:Android how to create the stack kind of image backgroundsAndroid如何创建堆栈类型的图像背景
【发布时间】:2013-01-21 13:18:00
【问题描述】:

我正在开发一个应用程序,我需要在其中创建相册并在 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>

【问题讨论】:

  • 找到解决方案了吗?

标签: android android-layout android-imageview android-xml


【解决方案1】:

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

【讨论】:

  • 是的,但我怎样才能对齐图像以获得这种效果。我需要一个可扩展的解决方案
  • 将您的图像对齐到背景图像的底部。
【解决方案2】:

我使用位图来创建堆栈视图并将其显示在图像视图中。您可以基于此将位图保存为资源,然后将其添加到 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);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-07-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多