2013-02-06 34 views
3

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

enter image description here

我尝试了这一点,但不是它的工作:

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

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

你找到解决办法吗? –

回答

0

将您的相册缩略图放在一张虚拟图像上(其中包含差异对齐中的2或3张图像)。

+0

是的,但我怎么能对齐图像来获得这种效果。我需要一个可扩展的解决方案 – sukarno

+0

将您的图像对齐背景图像的底部。 – DcodeChef

0

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

enter image description here

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