Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/203.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 组合多个抽绳_Android_Drawable - Fatal编程技术网

Android 组合多个抽绳

Android 组合多个抽绳,android,drawable,Android,Drawable,我有多个可绘制图形,并希望将其合并为一个可绘制图形(例如,4个正方形以创建一个大正方形,如Windows徽标:)。我怎样才能做到这一点?您可以使用表格布局或一些线性布局来做到这一点。但是,如果您想在ImageView中创建要使用的单个图像,则必须手动创建位图;这并不难: Bitmap square1 = BitmapFactory.decodeResource(getResources(), R.drawable.square1); Bitmap square2 = BitmapFactory.

我有多个可绘制图形,并希望将其合并为一个可绘制图形(例如,4个正方形以创建一个大正方形,如Windows徽标:)。我怎样才能做到这一点?

您可以使用
表格布局或一些
线性布局来做到这一点。但是,如果您想在
ImageView
中创建要使用的单个图像,则必须手动创建
位图
;这并不难:

Bitmap square1 = BitmapFactory.decodeResource(getResources(), R.drawable.square1);
Bitmap square2 = BitmapFactory.decodeResource(getResources(), R.drawable.square2);
Bitmap square3 = BitmapFactory.decodeResource(getResources(), R.drawable.square3);
Bitmap square4 = BitmapFactory.decodeResource(getResources(), R.drawable.square4);

Bitmap big = Bitmap.createBitmap(square1.getWidth() * 2, square1.getHeight() * 2, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(big);
canvas.drawBitmap(square1, 0, 0, null);
canvas.drawBitmap(square2, square1.getWidth(), 0, null);
canvas.drawBitmap(square3, 0, square1.getHeight(), null);
canvas.drawBitmap(square4, square1.getWidth(), square1.getHeight(), null);

我甚至没有编译上面的代码;我只是告诉你怎么做。我还假设你们有同样尺寸的方形可拉丝。请注意,名为
big
的位图可以在任何需要的地方使用(例如
ImageView.setImageBitmap()
)。

您可以使用它来完成此操作。

以下是有关的开发人员指南。它用图片和可运行的代码详细讨论了这一点。谢谢,我如何用这个画布创建可绘制的?你说的可绘制是什么意思?一个
可绘制的
类实例?如果是这样,您可以使用
BitmapDrawable
。请尽量说得更具体些。对不起,当然是拖拉课。4个输入可绘制实例和一个输出。是的,然后可以使用
BitmapDrawable