2012-07-04 7 views
8

여러 드로어 블을 하나의 드로어 블에 결합하고자합니다 (예 : 4 개의 사각형을 사용하여 Windows 로고와 같은 큰 사각형 하나 생성). 어떻게해야합니까?여러 드로어 블 합치기

+1

다음은 [Drawable Resources] (http://developer.android.com/guide/topics/resources/drawable-resource.html)에 대한 개발자 안내서입니다. 그것은 그림과 실행 가능한 코드로 훌륭한 세부 사항을 설명합니다. – Sam

답변

14

TableLayout 또는 일부 LinearLayout을 사용하여이를 수행 할 수 있습니다. 그러나 원하는 경우 ImageView 안에 하나의 이미지를 만들어서 수동으로 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); 

나는 위의 코드를 컴파일하지 않았다. 어떻게 할 수 있는지 보여줄뿐입니다. 나는 또한 같은 치수를 가진 정사각형 드로어 블을 모두 가지고 있다고 가정합니다. big 비트 맵을 원하는 곳 어디에서나 사용할 수 있습니다 (예 : ImageView.setImageBitmap()).

+0

감사합니다.이 캔버스로 드로어 블을 어떻게 만듭니 까? – arts777

+0

드로어 블 (Drawable)이란 무엇입니까? 'Drawable' 클래스 인스턴스? 그렇다면'BitmapDrawable'을 사용할 수 있습니다. 더 구체적으로 시도하십시오. – Cristian

+0

미안하지만 당연히 Drawable 클래스입니다. 4 입력 Drawable 인스턴스 및 하나의 출력. – arts777