activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<com.example.viewex01.MyView5
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RelativeLayout>
MainActivity.java
package com.example.viewex01;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.Menu;
import android.view.View;
public class MainActivity2 extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
MyView5.java
package com.example.viewex01;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.View;
public class MyView5 extends View {
public MyView5(Context context) {
super(context);
// TODO Auto-generated constructor stub
System.out.println("MyView2(Context context) 호출");
}
public MyView5(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
System.out.println("MyView2(Context context, AttributeSet attrs) 호출");
}
@Override
protected void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
// super.onDraw(canvas);
Paint Pnt = new Paint(Paint.ANTI_ALIAS_FLAG);
// 캡모양테스트
Pnt.setColor(Color.BLUE);
Pnt.setStrokeWidth(16);
canvas.drawLine(50, 30, 240, 30, Pnt);
Pnt.setStrokeCap(Paint.Cap.ROUND);
canvas.drawLine(50, 60, 240, 60, Pnt);
Pnt.setStrokeCap(Paint.Cap.SQUARE);
canvas.drawLine(50, 90, 240, 90, Pnt);
// 조인모양테스트
Pnt.setColor(Color.BLACK);
Pnt.setStrokeWidth(20);
Pnt.setStyle(Paint.Style.STROKE);
Pnt.setStrokeJoin(Paint.Join.MITER);
canvas.drawRect(50, 150, 90, 200, Pnt);
Pnt.setStrokeJoin(Paint.Join.BEVEL);
canvas.drawRect(120, 150, 160, 200, Pnt);
Pnt.setStrokeJoin(Paint.Join.ROUND);
canvas.drawRect(190, 150, 230, 200, Pnt);
}
}
'Android' 카테고리의 다른 글
그리기 객체 - Bitmap (0) | 2013.03.29 |
---|---|
캔버스 - setStyle (0) | 2013.03.29 |
캔버스 -AntiAlias (0) | 2013.03.29 |
캔버스 - 복잡한 도형 그리기 (0) | 2013.03.29 |
캔버스(canvas) (0) | 2013.03.29 |