2013-02-06 35 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);