ShapeEx.java
package net.itisn.com;
import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
public class ShapeEx extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);//안드로이드의 main 즉 엔트리 포인트.
this.requestWindowFeature(Window.FEATURE_NO_TITLE);//제목이 없음
//this.requestWindowFeature
setContentView(new ShapeView(this));
}
}
ShapeView.java
package net.itisn.com;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.drawable.shapes.OvalShape;
import android.view.View;
public class ShapeView extends View {
public ShapeView(Context context) {
super(context);
// TODO Auto-generated constructor stub
//백그라운드 색상 휜생
this.setBackgroundColor(Color.WHITE);
}
@Override //view클래스에 있는 메소드를 다 가져옴.
protected void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
super.onDraw(canvas);
//그림객체를 만들어보자
Paint paint = new Paint();
paint.setAntiAlias(true);
//선을 그려보자!!
paint.setStrokeWidth(2);// 선의 굵기
paint.setStyle(Paint.Style.STROKE); //스타일 지정
paint.setColor(Color.argb(255 , 255 , 0, 0)); //색깔
canvas.drawLine(160, 50, 10, 190, paint); //삼각형
canvas.drawLine(160, 50, 310, 190, paint);
canvas.drawLine(10 , 190, 310, 190, paint);
canvas.drawLine(30 , 190, 30, 350, paint); //사각형
canvas.drawLine( 290, 190, 290, 350, paint);
canvas.drawLine(30 , 350 , 290, 350, paint);
canvas.drawLine(30 , 190, 290, 350, paint); //X선
canvas.drawLine(290 , 190, 30, 350, paint);
//paint.setColor(Color.argb(0 , 250 , 0, 0)); //색깔
canvas.drawOval(new RectF(30, 190, 290, 350), paint);// 타원
//canvas.drawCircle(160, 270, 80, paint);
// //PATH 윈도우 API 사용 해서 그리기
// paint.setStyle(Paint.Style.STROKE);
// paint.setColor(Color.argb(255, 0 , 255,0));
// Path path = new Path();
// path.moveTo(55, 10);
// path.lineTo(200 , 350);
// canvas.drawPath(path, paint);
//
// paint.setColor(Color.argb(255, 0 ,0 , 255));
// paint.setStrokeWidth(1);// 선의 굵기
//
// canvas.drawRect(new Rect(100 , 100, 200 ,200), paint);
// canvas.drawRect(110 , 110, 220 ,220, paint);
//
// paint.setColor(Color.argb(255, 255 ,0 , 255));
// canvas.drawRoundRect(new RectF(55, 100,100 , 300 ),
// 10, 10 , paint);
}
}
'안드로이드' 카테고리의 다른 글
사과농장에 안드로이드 테블릿 키우기[LG Gpad v410] (0) | 2016.02.13 |
---|---|
[Android] 지하철 어플 만들기 1탄(탭레이아웃) (0) | 2010.08.26 |
[Android]AlertDialog 옵티머스Q, 안드로1 구분하기 (0) | 2010.08.24 |
[Android]그림 붙이고 토스트 날리기. (0) | 2010.08.23 |
[안드로이드] 글자쓰기 (0) | 2010.08.16 |