관리 메뉴

moozi

안드로이드 그래픽 본문

안드로이드개발강좌

안드로이드 그래픽

moozi 2015. 11. 18. 09:23

package com.naver.combo2b_28;

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.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(new MyGraphic(this));
    }

    //inner class
    private static class MyGraphic extends View {
        public MyGraphic(Context context){
            super(context);
        }

        protected void onDraw(Canvas canvas){
            super.onDraw(canvas);

            // Paint생성
            Paint paint = new Paint();
            paint.setAntiAlias(true);//테두리를 부드럽게.
            paint.setColor(Color.RED);//색상설정

            //직선 (시작x, 시작y, 끝x, 끝y, paint)
            canvas.drawLine(10,10, 300, 10, paint);

            //사각형
            Rect rect1=new Rect(10,50,110, 150);
            canvas.drawRect(rect1, paint);

            //원 (중심x, 중심y, 반지름, paint)
            canvas.drawCircle(60, 220, 50, paint);

            //꺽은선(path)
            paint.setStyle(Paint.Style.STROKE);//색을 채우지 않음
            Path path1=new Path();
            path1.moveTo(10, 290);//시작하는 점
            path1.lineTo(60, 340);
            path1.lineTo(110, 290);
            path1.lineTo(160, 340);
            canvas.drawPath(path1, paint);

            //글자(텍스트, x좌표, y좌표, paint);
            canvas.drawText("android", 10, 390, paint);

 

        }

    }
}

'안드로이드개발강좌' 카테고리의 다른 글

구글맵  (0) 2017.05.01
안드로이드 그래픽 터치이벤트  (0) 2015.11.25
구글맵 마커 아이콘 red-dot  (0) 2015.11.17
genymotion gapp설치  (0) 2015.11.12
runOnUiThread를 활용한 파일다운로드  (0) 2015.11.10
Comments