Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
Tags
- HTML
- OGNL
- 이클립스
- Eclips
- Java
- Graphic
- 예외처리
- 국제화
- struts2
- 어노테이션
- layout
- JavaScript
- 생성자
- 안드로이드
- mybatis
- 에러페이지
- 기본
- JSP
- Spring
- 전화걸기
- 메소드
- Android
- 배열
- 오버로딩
- Menu
- 메서드
- oracle
- AWT
- paint
- 클래스
Archives
- Today
- Total
note
Android Paint로 그림그리기 본문
main.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> </LinearLayout>
main Activity
package com.hardrock.hellotest; import android.app.Activity; import android.os.Bundle; import android.graphics.Canvas; import android.content.Context; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Path; import android.graphics.RectF; import android.view.View; public class PaintDemo extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(new ViewWithDraw(this)); } private static class ViewWithDraw extends View{ public ViewWithDraw(Context context){ super(context); } @Override protected void onDraw(Canvas canvas){ //백그라운드 색깔지정 canvas.drawColor(Color.BLACK); Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG); //draw Line mPaint.setColor(Color.RED); //도형의 색깔지정 mPaint.setStrokeWidth(10); //도형의 두께 canvas.drawLine(50, 0, 50, 100, mPaint); //시작 x 시작 y 끝x 끝y paint객체 mPaint.setColor(Color.GREEN); mPaint.setStrokeWidth(5); //alpha : 0(투명) ~255 (완전 불투명) for(int y = 30,alpha =255; alpha>2 ; alpha -=50, y+=10){ //alpha값 지정(투명도)를 지정 mPaint.setAlpha(alpha); canvas.drawLine(0,y,100,y,mPaint); } // draw Rect mPaint.setColor(Color.WHITE); // 테두리만 그린다. mPaint.setStyle(Paint.Style.STROKE); mPaint.setStrokeWidth(1); canvas.drawRect(120, 10, 120 + 80, 10 + 80, mPaint); //left top right bottom mPaint.setColor(Color.MAGENTA); // 내부를 채운다 mPaint.setStyle(Paint.Style.FILL); canvas.drawRect(220, 10, 220 + 80, 10 + 80, mPaint); // draw Arc(원호 원의 일부분) mPaint.setColor(Color.YELLOW); canvas.drawArc(new RectF(150, 120, 150 + 100, 120 + 100), 0, 50, true, mPaint); // 시작각도(0) , 끝각도(50), 중심사용여부(true) // draw Oval(타원도 포함한 원) mPaint.setColor(Color.GREEN); canvas.drawOval(new RectF(20, 250, 20 + 100, 250 + 50), mPaint); // draw RoundRect mPaint.setColor(Color.RED); canvas.drawRoundRect(new RectF(150, 250, 150 + 100, 250 + 50), 10, 10, mPaint);//라운드의 정도(10),(10) 포토샵Father효과임 // draw Path mPaint.setColor(Color.YELLOW); // 테두리만 그린다. mPaint.setStyle(Paint.Style.STROKE); mPaint.setStrokeWidth(2); Path mPath = new Path(); mPath.moveTo(0, 0); mPath.lineTo(30, 60); mPath.lineTo(-30, 60); mPath.close(); //전체 Path 가 위치할 x,y 좌표 mPath.offset(150, 360); canvas.drawPath(mPath, mPaint); } } }
'Android > 기본' 카테고리의 다른 글
Android FileSearch Gallery(사진선택) (0) | 2012.02.01 |
---|---|
Android Animaiton 으로 효과 (3) | 2012.02.01 |
Android Preferences 읽고 쓰기(환경설정) (0) | 2012.02.01 |
안드로이드 환경설정Preferences , 메뉴 (0) | 2012.01.31 |
RSS 가져오기(뉴스) (1) | 2012.01.31 |