您的位置:首页 > 移动开发 > Android开发

android 如何获取launcher的workspace中的每一个celllayout的位图???

2012-05-24 16:08 316 查看
我要做一个3D旋转桌面,现在已经绘制好立方体,往上面贴好纹理了,不过纹理是其他图片,现在我想要获取launcher的workspace中的每一个celllayout的位图,然后将其作为纹理贴到立方体上。

也就是说,我现在不知道如何将workspace中的每一个分屏view(celllayout)转换成位图。

我已经尝试过的方法有两个,都不行: 注:下面的cell1来自launcher.xml中的<include android:id="@+id/cell1" layout="@layout/workspace_screen" />这一句,具体见层级观察器的截图。

1.
View view = findViewById(R.id.cell1);

Bitmap bit = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);//这一句话报错,说view的宽高是0.

Canvas c = new Canvas(bit);

view.draw(c);

if(bit==null)

Log.v(TAG,"mBitmap is null");

else

Log.v(TAG,"mBitmap is not null");


2.
View tempView=(View)findViewById(R.id.cell1);

tempView.setDrawingCacheEnabled(true);

tempView.measure( MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),

MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));//这一句话报错,说tempView大小不确定神马的。

tempView.layout(0, 0, tempView.getMeasuredWidth(),tempView.getMeasuredHeight());

tempView.buildDrawingCache();

mBitmap[0]= tempView.getDrawingCache();

if(mBitmap[0]==null)

Log.v(TAG,"mBitmap is null");


[img=http://img.my.csdn.net/uploads/201205/24/13378284_7309.jpg][/img]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: