52
To be an Android Expert 문양세 강원대학교 IT대학 컴퓨터학부

13. Application Resources - Part II

Embed Size (px)

Citation preview

Page 1: 13. Application Resources - Part II

To be an Android Expert

문양세강원대학교 IT대학 컴퓨터학부

Page 2: 13. Application Resources - Part II

Resource Types◦ Animation

◦ Color, Color State List

◦ Drawable

◦ Stringg

◦ Dimension

2

Page 3: 13. Application Resources - Part II

Drawable은 화면에 그릴 수 있고 getDrawable() 등의 API를 사용하여 Drawable은 화면에 그릴 수 있고, getDrawable() 등의 API를 사용하여

얻을 수 있는 그래픽의 일반적 개념이다. Drawable의 종류 Drawable의 종류

◦ Bitmap File (BitmapDrawable): A bitmap graphic file (.png, .jpg, or .gif).◦ Nine-Patch File (NinePatchDrawable): A PNG file with stretchable regions to

allow image resizing based on content (.9.png).◦ Layer List (LayerDrawable ): A Drawable that manages an array of other

Drawables These are drawn in array order so the element with the largestDrawables. These are drawn in array order, so the element with the largest index is be drawn on top.

◦ State List (StateListDrawable): An XML file that references different bitmap graphics for different states (for example, to use a different image when a button is pressed).

3

Page 4: 13. Application Resources - Part II

Drawable의 종류 (계속) Drawable의 종류 (계속)◦ Level List (LevelListDrawable): An XML file that defines a Drawable that

manages a number of alternate Drawables, each assigned a maximum numerical value.

◦ Transition Drawable (TransitionDrawable): An XML file that defines a Drawable that can cross-fade between two drawable resourcesDrawable that can cross fade between two drawable resources.

◦ Clip Drawable (ClipDrawable): An XML file that defines a Drawable that clips another Drawable based on this Drawable's current level value.

◦ Scale Drawable (ScaleDrawable): An XML file that defines a Drawable that changes the size of another Drawable based on its current level value.

4

Page 5: 13. Application Resources - Part II

Drawable의 종류 (계속) Drawable의 종류 (계속)◦ Shape Drawable (ShapeDrawable): An XML file that defines a geometric

shape, including colors and gradients.◦ See also AnimationDrawable: Tween Animation, Frame Animation

5

Page 6: 13. Application Resources - Part II

안드로이드는 ( f d) j ( t bl ) if 안드로이드는 png (preferred), jpg (acceptable), gif (discouraged)의 세 가지 비트맵 이미지를 지원한다.

6

Page 7: 13. Application Resources - Part II

예제 예제

7

Page 8: 13. Application Resources - Part II

하나의 비 맵 파일을 지정하 해당 비 맵 파일에 하나의 비트맵 파일을 지정하고, 해당 비트맵 파일에

대한 다양한 효과(dithering, tiling 등)를 부여한다.대한 다양한 과 g, g 등 를 부여한다

8

Page 9: 13. Application Resources - Part II

Syntax

9

Page 10: 13. Application Resources - Part II

resact.xml

10

Page 11: 13. Application Resources - Part II

11

Page 12: 13. Application Resources - Part II

AndroidManifest.xml

strings mlstrings.xml

ResourceAct.java

12

Page 13: 13. Application Resources - Part II

13

Page 14: 13. Application Resources - Part II

확대가능한(stretchable) 비트맵 이미지이다 확대가능한(stretchable) 비트맵 이미지이다. PNG 파일(.9.png)로서, 확대가능한 섹션을 정의하여, 디스플레이 시점

에 텍스트 길이 등에 맞도록 크기 변경이 가능한 특성을 가진다에 텍스트 길이 등에 맞도록 크기 변경이 가능한 특성을 가진다. 자세한 내용은 “Graphics”의 “2D Graphics”를 참조한다.

14

Page 15: 13. Application Resources - Part II

9-patch 이미지를 그리는 tool (draw9patch.bat)p 이미지를 리는 ( p )

15

Page 16: 13. Application Resources - Part II

Drawable의 배열로서, 순서에 따라 화면에 나타난다. 배의 배열 서, 순서에 따라 화면에 나타난다 배

열의 맨 마지막의 drawable이 화면 맨 위에 나타난다.

16

Page 17: 13. Application Resources - Part II

Syntax (top right bottom left: 위치) Syntax (top, right, bottom, left: 위치)

17

Page 18: 13. Application Resources - Part II

18

Page 19: 13. Application Resources - Part II

ResourceActXMLBitmap.java

19

Page 20: 13. Application Resources - Part II

(Color State List와 유사하게) 오브젝트의 상태에 따라 다( 와 유사하게) 젝 의 상태에 따라 다

른 그래픽을 보여주고자 할 때 사용한다.

20

Page 21: 13. Application Resources - Part II

Syntax Syntax

21

Page 22: 13. Application Resources - Part II

R A tXMLBit jResourceActXMLBitmap.java

22

Page 23: 13. Application Resources - Part II

23

Page 24: 13. Application Resources - Part II

여러 개의 Drawable에 대해 숫자를 레벨로 부여하고, 여러 개의 에 대해 숫자를 레벨 부여하 ,setLevel()에 의해 지시된 레벨의 Drawable을 로드한다.

대표적인 예가 배터리 레벨을 나타내는 이미지 집합이다 대표적인 예가 배터리 레벨을 나타내는 이미지 집합이다.

24

Page 25: 13. Application Resources - Part II

Syntax (min-max 사이에 드는 아이템이 로드된다.)Sy ta ( a 사이에 는 아이템이 로 된다 )

25

Page 26: 13. Application Resources - Part II

상태 On/Off 예제상태 O /O 예제

배터리 레벨 관리 예제 배터리 레벨 관리 예제

26

Page 27: 13. Application Resources - Part II

두 개의 Drawable 객체에 대해 cross-fade를 지원한다. (하나가 나타난 후, 다른 것으로 서서히 바뀜)

두 개 이상은 지원하지 않는다 두 개 이상은 지원하지 않는다.

27

Page 28: 13. Application Resources - Part II

Transition을 정의하는 XML 파일을 작성한다.

28

Page 29: 13. Application Resources - Part II

정의한 transition을 layout에 포함시킨다.(본 예는 새로운 FrameLayout에 ImageButton으로 표현하였다.)

29

Page 30: 13. Application Resources - Part II

Transition을 수행한다. (1/2)(본 예는 새로운 Activity를 만들어 수행하였다.)

resact.xml

AndroidManifest.xml

strings.xml

30

g

Page 31: 13. Application Resources - Part II

Transition을 수행한다. (2/2)a s t o 을 수행한다 ( / )ResourceAct.java

31

Page 32: 13. Application Resources - Part II

실행 결과실행 결과

32

Page 33: 13. Application Resources - Part II

지정된 Drawable의 일부를 clip할 수 있는 Drawable이다.지정된 의 일부를 p할 수 있는 이다

Progress Bar 등을 구현할 때 사용할 수 있다.

33

Page 34: 13. Application Resources - Part II

Syntaxy

34

Page 35: 13. Application Resources - Part II

주어진 Drawable의 크기를 조절할 수 있는 Drawable이다.주어진 의 기를 절할 수 있는 이다

35

Page 36: 13. Application Resources - Part II

일반적 모양(generic shape)을 정의하는 Drawable이다.일반적 양(g p )을 정의하는 이다

36

Page 37: 13. Application Resources - Part II

Syntaxy

37

Page 38: 13. Application Resources - Part II

Shape을 정의하는 XML 파일을 작성한다.S ape을 정의하는 파일을 작성한다

• gradient: 경사진 차츰 상승하는

38

• gradient: 경사진, 차츰 상승하는

Page 39: 13. Application Resources - Part II

정의한 Shape을 기존 View에 적용한다.정의한 S ape을 기존 e 에 적용한다resact.xml

39

Page 40: 13. Application Resources - Part II

Resource Types◦ Animation

◦ Color, Color State List

◦ Drawable

◦ Stringg

◦ Dimension

40

Page 41: 13. Application Resources - Part II

지금까지 계속 사용한 strings.xml을 의미한다.지금까지 계속 사용한 st gs 을 의미한다

41

Page 42: 13. Application Resources - Part II

스트링의 배열(an array of strings)을 선언한다.스트링의 배열(a a ay o st gs)을 선언한다

SyntaxSyntax

42

Page 43: 13. Application Resources - Part II

사용 예제사용 예제strings.xml

ResourceActTransition.java

43

Page 44: 13. Application Resources - Part II

실행 화면실행 화면

44

Page 45: 13. Application Resources - Part II

따옴표가 포함된 스트링 사용법따옴표가 포함된 스트링 사용법

String format(String Object ) 사용법 String.format(String, Object, …) 사용법

태 사용 HTML 태그 사용

45

Page 46: 13. Application Resources - Part II

Resource Types◦ Animation

◦ Color, Color State List

◦ Drawable

◦ Stringg

◦ Dimension

46

Page 47: 13. Application Resources - Part II

객체의 크기를 지정하는 단위 (10px, 2in, 5sp 등) 측정 단위 종류

◦ px: 픽셀 스크린 상의 실제 픽셀에 대응px: 픽셀, 스크린 상의 실제 픽셀에 대응

◦ in: 인치, 물리적 크기

◦ mm: 밀리미터 물리적 크기mm: 밀리미터, 물리적 크기

◦ pt: 포인트, 1/72 인치, 물리적 크기

◦ dp: Density-independent Pixel 추상적 단위◦ dp: Density independent Pixel, 추상적 단위, 1dp는 160dpi 스크린에서 1픽셀에 해당

◦ sp: Scale-independent Pixel dp와 단위가 같으나 “사용자의sp: Scale independent Pixel, dp와 단위가 같으나, 사용자의폰트 크기 설정에 의해 스케일된다.” 폰트 크기 설정 시 사용 권장

47

Page 48: 13. Application Resources - Part II

위치 및 레퍼런스 방법위치 및 레퍼런스 방법

Syntax

48

Page 49: 13. Application Resources - Part II

t lresact.xml

49

Page 50: 13. Application Resources - Part II

ResourceAct.java

50

Page 51: 13. Application Resources - Part II

51

Page 52: 13. Application Resources - Part II

52