안녕하세요
선택한 영역을 표시하고 싶으신거지요?
아래 간단한 예제소스 입니다.
사용 방법은
Context ctx = this;
SignView sw = new SignView(ctx);
ll_contain,addView(sw); // 현재 보이는 레이아웃 객체에 붙여주세요
제가 올린 소스의 경우 라인을 그리는 것인데 질문자님이 표현하고자 하는 방식(도형, 선긋기)으로 바꾸셔도 됩니다.
수고하세요!
package kr.co.test;
import java.util.ArrayList;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
public class SignView extends View
{
Paint p = new Paint();
ArrayList<Vertex> list = new ArrayList<Vertex>();
// 서명 여부를 확인 변수
public int count;
// 생성자
public SignView(Context context)
{
super(context);
p.setColor(Color.BLACK);
p.setAntiAlias(true);
p.setStrokeWidth(5);
count = 0;
}
public class Vertex
{
// 생성자
public Vertex(float x, float y, boolean stat)
{
this.x = x;
this.y = y;
this.stat = stat;
}
float x;
float y;
boolean stat;
}
@Override
public void onDraw(Canvas can)
{
// 캔버스 배경 투명하게
can.drawColor(Color.TRANSPARENT);
for(int i = 0 ; i < list.size() ; i++)
{
Vertex v = list.get(i);
if(v.stat == true)
{
// 라인 그리기
can.drawLine(list.get(i - 1).x, list.get(i - 1).y, list.get(i).x, list.get(i).y, p);
}
}
}
@Override
public boolean onTouchEvent(MotionEvent e)
{
count++;
if(e.getAction() == MotionEvent.ACTION_DOWN)
{
list.add(new Vertex(e.getX(), e.getY(), false));
}
if(e.getAction() == MotionEvent.ACTION_MOVE)
{
list.add(new Vertex(e.getX(), e.getY(), true));
invalidate(); // 화면갱신
}
return true;
}
}