관리 메뉴

moozi

그래픽코드 본문

안드로이드개발강좌

그래픽코드

moozi 2015. 4. 1. 16:51

package com.naver.graphictest;

 

import android.content.Context;

import android.graphics.Canvas;

import android.graphics.Color;

import android.graphics.Paint;

import android.support.v7.app.ActionBarActivity;

import android.os.Bundle;

import android.view.Menu;

import android.view.MenuItem;

import android.view.View;

 

class MyGraphic extends View{

    private Paint paint; //붓역할을 하는 paint선언.

 

    //생성자

    public MyGraphic(Context context){

        super(context);//부모생성자호출

        paint = new Paint();//paint인스턴스 생성

        paint.setColor(Color.RED);//빨간색으로 지정

    }

 

    //그림을 그리는 메서드

    protected void onDraw(Canvas canvas){

        super.onDraw(canvas);

        canvas.drawRect(100, 100, 200, 200, paint);

 

        //stroke적용

        paint.setStyle(Paint.Style.STROKE);

        canvas.drawRect(100, 210, 200, 310, paint);

 

    }

}

 

 

 

public class MainActivity extends ActionBarActivity {

 

    @Override

     protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        //setContentView(R.layout.activity_main);

 

        //그래픽클래스 인스턴스 생성

        MyGraphic mg = new MyGraphic(this);

        setContentView(mg);

    }

 

 

    @Override

    public boolean onCreateOptionsMenu(Menu menu) {

        // Inflate the menu; this adds items to the action bar if it is present.

        getMenuInflater().inflate(R.menu.menu_main, menu);

        return true;

    }

 

    @Override

    public boolean onOptionsItemSelected(MenuItem item) {

        // Handle action bar item clicks here. The action bar will

        // automatically handle clicks on the Home/Up button, so long

        // as you specify a parent activity in AndroidManifest.xml.

        int id = item.getItemId();

 

        //noinspection SimplifiableIfStatement

        if (id == R.id.action_settings) {

            return true;

        }

 

        return super.onOptionsItemSelected(item);

    }

}

 

 

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

안드로이드 스튜디오에서 JSON 테스트  (0) 2015.04.30
BlurMaskFilter가 적용되지 않을 때  (0) 2015.04.24
nfc reader writer  (0) 2014.12.04
NFC 웹페이지 띄우기  (0) 2014.11.26
무음/진동 처리  (0) 2014.11.21
Comments