问题描述
我开发一个应用程序,我需要创建相册,并在GridView显示出来。现在我只是显示他们没有任何背景,但我需要一个背景,专辑封面,这样它看起来像一堆照片。背景是这样的:
我尝试了这一点,但不是它的工作:
首先,我创建了一个这样的背景:
<形状的xmlns:机器人=http://schemas.android.com/apk/res/android>
[固体机器人:颜色=#FFFFFF/>
<中风
机器人:宽=1DP
机器人:颜色=#000000/>
<填充
机器人:底部=1DP
机器人:左=1DP
机器人:右=1DP
机器人:顶部=1DP/>
< /形状>
然后,我用一层名单提请堆栈轮换:
<层列表的xmlns:机器人=http://schemas.android.com/apk/res/android>
<旋转
机器人:可绘制=@可绘制/ thumb_bg
机器人:fromDegrees =90
机器人:pivotX =50%
机器人:pivotY =50%
机器人:toDegrees =100/>
<旋转
机器人:可绘制=@可绘制/ thumb_bg
机器人:fromDegrees =90
机器人:pivotX =50%
机器人:pivotY =50%
机器人:toDegrees =110/>
<旋转
机器人:可绘制=@可绘制/ thumb_bg
机器人:fromDegrees =90
机器人:pivotX =50%
机器人:pivotY =50%
机器人:toDegrees =120/>
< /层列表>
我用位图创建堆栈视图,并显示在一个ImageView的。您可以在此基础上,保存位图资源然后将其添加在GridView或者用它在GridView的适配器getView我想。
位图M1C = BitmapFactory.de codeResource(getResources(),R.drawable.cat_13);
位图M2C = BitmapFactory.de codeResource(getResources(),R.drawable.cat_13);
INT W = m1c.getWidth();
INT H = m1c.getHeight();
矩阵MTX =新的Matrix();
mtx.postRotate(4);
位图rotatedBMP = Bitmap.createBitmap(M1C,0,0,W,H,MTX,真);
矩阵MTX2 =新的Matrix();
mtx2.postRotate(-4);
位图rotatedBMP2 = Bitmap.createBitmap(M1C,0,0,W,H,MTX2,真);
帆布comboImage =新的Canvas(rotatedBMP);
comboImage.drawBitmap(rotatedBMP2,-10,-10,空);
comboImage.drawBitmap(M2C,10,10,NULL);
ImageView的形象=(ImageView的)findViewById(R.id.imageView1);
image.setImageBitmap(rotatedBMP);
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>
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);
这篇关于的Android如何创建堆栈样的形象背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!