NinePatch 용량 최적화는 sdk/tools/draw9patch.bat 이용
1. 나인패치 이미지 준비 - test.9.png
2. 버튼 Listener
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 9patch 적용 | |
public void SetNine(View v) { | |
View layoutView = findViewById(R.id.view); | |
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.test); | |
if (bitmap.getNinePatchChunk() == null) | |
return; | |
// chunk::array형 이미지정보(반드시 NinePatch정보를 포함해야 not null) | |
byte[] chunk = bitmap.getNinePatchChunk(); | |
NinePatch patch = new NinePatch(bitmap, chunk, null); | |
NinePatchDrawable drawable = new NinePatchDrawable(getResources(), patch); | |
// Image 설정 | |
drawable.getPaint().setAntiAlias(false); // default::false | |
drawable.getPaint().setDither(false); // default::false | |
drawable.getPaint().setFilterBitmap(false); // Filter끄기 _ default::true | |
layoutView.setBackground(drawable); | |
} |
3. Image 설정 부분 code를 xml로 정의해서 사용할 수도 있음(drawable폴더 생성 후 작성)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Bitmap | |
android:src="@drawable/bitmap" | |
android:antialias="false" | |
android:dither="false" | |
android:filter="false" | |
android:tilemode="clamp"/> |
'Android' 카테고리의 다른 글
[android]Changes for v4 Support Library _ revision 13 (May 2013) (0) | 2013.05.22 |
---|---|
[android]Button의 Drawable을 SourceCode로 작성 (0) | 2013.05.15 |
[android]convert intent to string(uri) _ intent를 String(Uri)값으로 변환하기 (0) | 2013.05.06 |
[android]view 절대좌표 구하기 (1) | 2013.04.22 |
[android]manifest permission constants (0) | 2013.03.05 |