개발/안드로이드
안드로이드 paint 속성
by darksilber
2016. 1. 19.
출처 - http://baramziny.tistory.com/entry/안드로이드-텍스트-그리기
텍스트 출력하기 안드로이드에서 텍스트를 출력하는 메서드는 캔버스 클래스의 다음 4가지로 오버로딩 되어있다.| void | drawText(String text, float x, float y, Paint paint) Draw the text, with origin at (x,y), using the specified paint. | | void | drawText(CharSequence text, int start, int end, float x, float y, Paint paint) Draw the specified range of text, specified by start/end, with its origin at (x,y), in the specified Paint. | | void | drawText(char[] text, int index, int count, float x, float y, Paint paint) Draw the text, with origin at (x,y), using the specified paint. | | void | drawText(String text, int start, int end, float x, float y, Paint paint) Draw the text, with origin at (x,y), using the specified paint. |
|
텍스트 속성 변경하기 안드로이드에서 텍스트의 여러가지 속성을 변경하는 paint의 메서드이다.
| void | setSubpixelText(boolean subpixelText) Helper for setFlags(), setting or clearing the SUBPIXEL_TEXT_FLAG bit
//?? | | void | setTextAlign(Paint.Align align)Set the paint's text alignment. 문자열의 수평정렬을 지정한다. default 값은 왼쪽이며, LEFT,CENTER,RIGHT 를 지정할 수 있다. 지정값은 enum으로 안드로이드에 저장되어 다음과 같다. | Enum Values |
|---|
| Paint.Align | CENTER | The text is drawn centered horizontally on the x,y origin | | Paint.Align | LEFT | The text is drawn to the right of the x,y origin | | Paint.Align | RIGHT | The text is drawn to the left of the x,y origin |
똑같은 수평 좌표 100에 세 개의 문자를 출력한다고 하자. 그렇다면, 이 100이라는 좌표가 문자열에 어디에 위치하는 가는 위의 기준에 따라 정해 줄 수가 있다. 일반적인 문자열은 왼쪽정렬을 사용하며, 자릿수 같은 경우에는 오른쪽 정렬을 사용한다. 수직정렬은 글자의 베이스를 기준으로 좌표를 설정한다. 그 이유는 문자가 위로 정렬되거나, 혹은 가운데로 정렬되었을 경우에는 가독성이 떨어지기 때문이다. 그러므로 문자열을 출력할 때, y좌표를 0으로 전달하면 화면 상단에 출력되는 것이 아니라, 상단보다 위쪽으로 출력되어 문자열이 보이지 않게 된다. | | void | setTextScaleX(float scaleX) Set the paint's horizontal scale factor for text.
장평을 조절한다. | | void | setTextSize(float textSize) Set the paint's text size.
글자의 크기를 조절한다. | | void | setTextSkewX(float skewX) Set the paint's horizontal skew factor for text.
글자의 기울기를 조정하며, -일경우에는 왼쪽, +일경우에는 오른 쪽으로 기울여지게 된다. 이때의 각도는 라디안이 기준이다. | | Typeface | setTypeface(Typeface typeface)Set or clear the typeface object. 글자의 모양을 결정하는 가장 중요한 정보는 타입페이스이다. 타입페이스란 고유의 글꼴에 대한 이름이다. Typeface 객체는 별도의 생성자 없이 다음 정적 메서드로 생성해야 한다. | static Typeface | create(String familyName, int style) Create a typeface object given a family name, and option style information. | | static Typeface | create(Typeface family, int style) Create a typeface object that best matches the specified existing typeface and the specified Style. |
페이스 이름은 아래와 같이 상수로 정의 되어 있다, Typeface,DEFAULT , Typeface.DEFAULT_BOLD, Typeface.MONOSPACE, Typeface.SANS_SERIF, Typeface.SERIF 스타일은 아래와 같이 typeface 에 정의 되어 있다. Typeface,BOLD, Typeface,BOLD_ITALIC, Typeface.ITALIC, Typeface.NORMAL 각 페이스 이름 별로 출력한 그림은 아래와 같다. 커스텀 폰트 지정하기.
1. 적당한 폰트 파일을 구하여 프로젝트의 assets 폴더로 복사한다. 2. 다음 정적 클래스로 폰트를 읽어 드린다.
첫번 째 인수로는 AssetManager 객체를 전달한다. AssetManger는 Resources 클래스에 정의된 정적 메소드인 getAsset()을 이용해서 불러오면 된다. AssetManger는 다음과 같이 설명되어 있다. Provides access to an application's raw asset files; see Resources for the way most applications will want to retrieve their resource data. This class presents a lower-level API that allows you to open and read raw files that have been bundled with the application as a simple stream of bytes. 이후의 방법은 위의 Paint객체의 메소드로 불러온 Typeface를 지정하여 사용하면 된다. | | void | setUnderlineText(boolean underlineText) Helper for setFlags(), setting or clearing the UNDERLINE_TEXT_FLAG bit
밑줄에 관한 것이다. | | Xfermode | setXfermode(Xfermode xfermode) Set or clear the xfermode object. |
|
댓글