2012-07-04 17 views
8

複数のドロウアブルがあり、それを1つのドロウアブルに結合する必要があります(たとえば、Windowsのロゴのように大きな四角形を作成するには4つの正方形)。これどうやってするの?複数のドロウアブルを結合する

+1

[Drawable Resources](http://developer.android.com/guide/topics/resources/drawable-resource.html)の開発者向けガイドです。これは、画像と実行可能なコードでこれが素晴らしい詳細です説明します。 – Sam

答えて

14

TableLayoutまたはLinearLayoutを使用してこれを行うことができます。しかし、あなたが望むものが、ImageViewの中に1つのイメージを作成する場合は、Bitmapを手動で作成する必要があります。それは難しくありません:

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

私は上記のコードをコンパイルしていません。私はそれがどのようにできるかをあなたに示しています。私はまた、すべて同じ次元の正方形drawablesを持っていると仮定しています。 bigというビットマップは、好きな場所で使用できます(例:ImageView.setImageBitmap())。

+0

ありがとう、このキャンバスでドロアブルを作成するにはどうすればよいですか? – arts777

+0

ドロアブルはどういう意味ですか? 'Drawable'クラスのインスタンスですか?もしそうなら、あなたは 'BitmapDrawable'を使うことができます。より具体的にお試しください。 – Cristian

+0

申し訳ありませんが、もちろんDrawableクラスです。 4つの入力可能なインスタンスと1つの出力。 – arts777

5

LayerDrawableを使用すると、これを正確に行うことができます。