2007 2013 Kandroid
www.kandroid.org »
kandroid s/w fundamentals 교육 »
안드로이드 Platform 
▶ HTC Dream Platform Images
Nine-Patch Stretchable Image
작성자 invain
작성일 2008-06-02 (월) 23:40
ㆍ추천: 0  ㆍ조회: 2336      
IP: 218.xxx.168
 
 

Nine-Patch Stretchable Image

Android supports a stretchable bitmap image. This is a PNG image in which you define stretchable sections that Android will resize to fit the object at display time to accommodate variable sized sections, such as text strings. You typically assign this resource to the View's background. An example use of a stretchable image is the button backgrounds that Android uses; buttons must stretch to accommodate strings of various lengths.
A NinePatch drawing is a standard PNG image that includes a 1 pixel wide border. This border is used to define the stretchable and static areas of the screen. You indicate a stretchable section by drawing one or more 1 pixel wide black lines in the left or top part of this border. You can have as many stretchable sections as you want. The relative size of the stretchable sections stays the same, so the largest sections always remain the largest.
You can also define an optional drawable section of the image (effectively, the padding lines) by drawing a line on the right and bottom lines. If you do not draw these lines, the first top and left lines will be used.
If a View object sets this graphic as a background and then specifies the View object's text, it will stretch itself so that all the text fits inside the area designated by the right and bottom lines (if included, the first top and left lines otherwise). If the padding lines are not included, Android uses the left and top lines to define the writeable area.
Here is a sample NinePatch file used to define a button.
Raw ninepatch file showing the definition lines
This ninepatch uses one single stretchable area, and it also defines a drawable area.
Here are two buttons based on this graphic. Notice how the width and height of the button varies with the text, and the background image stretches to accommodate it.
Two buttons based on the NinePatch button background
Source file format: PNG — one resource per file
Resource source file location: res/drawable/some_name.9.png (must end in .9.png)
Compiled resource datatype: Resource pointer to a NinePatchDrawable.
Resource reference name:
  • Java R.drawable.some_file
  • XML @[package:]drawable.some_file
Example Code Use
Example XML code
Note that the width and height are set to "wrap_content" to make the button fit neatly around the text.
<Button id="@+id/tiny"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerInParent="true"
        android:text="Tiny"
        android:textSize="8sp"
        android:background="@drawable/my_button_background"/>

<Button id="@+id/big"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerInParent="true"
        android:text="Biiiiiiig text!"
        android:textSize="30sp"
        android:background="@drawable/my_button_background"/>
이름아이콘 예비쏘멤
2008-06-06 16:21
좋은 자료 감사드려요^^
   
 
덧글 쓰기 0
3500
※ 회원등급 레벨 0 이상 읽기가 가능한 게시판입니다.
    N     분류     제목    글쓴이 작성일 조회
47 Google IO: Anatomy & Physiology of an Android [1] 들풀 2008-06-06 2093
46 Ubuntu 8.04 vs. Fedora 9 invain 2008-06-04 1678
45 ELC2008 - Development of Mobile Linux Open Platform invain 2008-06-03 1019
44 Nine-Patch Stretchable Image [1] invain 2008-06-02 2336
43 구글 안드로이드 플랫폼 분석 [12] 성공하자 2008-05-28 7053
42 Development of Mobile Linux Open Platform 들풀 2008-05-14 1688
41 안드로이드 플랫폼 시작시의 Red Eye [4] invain 2008-05-09 2097
40 Spring 2008 Release of Sourcery G++ for ARM [2] invain 2008-04-17 1621
39 당신이 VM에 대해 알아야 하는 모든 것... [4] 들풀 2008-04-09 3577
38 Dalvik VM and SQlite 3.5.5 [4] 오호라 2008-03-14 2153
37 Tool to read Android binary XML files [1] 들풀 2008-03-09 2537
36 yaffs2포맷으로 System.img 및 userdata.img 생성 및 추출.. invain 2008-03-04 4635
35 Dalvik VM의 .dex [1] invain 2008-03-04 3009
34    Overview of ARM Jazelle DBX (Direct Bytecode eXecution) Tech [1] invain 2008-03-04 2193
33 [인베인] ARM EABI Port 들풀 2008-03-04 2122
32 [인베인] Android Emulator의 Internals 들풀 2008-03-04 2232
1234567