public class ReDraw1 extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_re_draw1);
}
class MyView extends View {
ArrayList<Vertex> Picture;
public MyView(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.re_draw1, menu);
return true;
}
public void onDraw(Canvas canvas) {
Paint Pnt = new Paint();
LinearGradient lshader = new LinearGradient(0, 0, 480, 0, Color.DKGRAY, Color.LTGRAY, TileMode.REPEAT);
Pnt.setShader(lshader);
canvas.drawRect(0, 0, getWidth(), getHeight(), Pnt);
Pnt.setShader(null);
Pnt.setStyle(Paint.Style.STROKE);
Pnt.setStrokeWidth(2);
Pnt.setColor(0x80ff0000);
for (int x = 0; x < 7; x++) {
for (int y = 0; y < 7; y++) {
Path path = new Path();
path.moveTo(x*70, y*70);
for (int dis = 32; dis > 1; dis--) {
switch (dis % 4) {
case 0:
path.rLineTo(dis*2, 0);
break;
case 3:
path.rLineTo(0, dis*2);
break;
case 2:
path.rLineTo(-dis*2, 0);
break;
case 1:
path.rLineTo(0, -dis*2);
break;
}
}
canvas.drawPath(path, Pnt);
}
}
Pnt.setColor(Color.BLACK);
Pnt.setStrokeWidth(3);
Pnt.setAntiAlias(true);
for (int i = 0; i < Picture.size(); i++) {
if ( Picture.get(i).Draw ) {
canvas.drawLine(Picture.get(i-1).x, Picture.get(i-1).y, Picture.get(i).x, Picture.get(i).y, Pnt);
}
}
}
@Override
public boolean onTouchEvent(MotionEvent event) {
// TODO Auto-generated method stub
if (event.getAction() == MotionEvent.ACTION_DOWN) {
Picture.add(new Vertex(event.getX(), event.getY(), true));
invalidate();
return true;
}
return false;
}
}
package com.example.redraw1;
public class Vertex {
float x;
float y;
boolean Draw;
Vertex(float ax, float ay, boolean ad) {
x = ax;
y = ay;
Draw = ad;
}
}
책에 있는 예제를 그대로 쳤는데 getWidth(), getHeight(), Picture.size(), Picture.get(), Picture.add(), invalidate()
클래스 정의를 보면 분명 존재하는 함수같은데 막상 .찍어보면 목록에 나오질 않구..
어떻게 해결해야 되는지 알려주시면 감사하겠습니다!