0
嗨每一個.. 在我的應用程序我已經成功畫線之間的兩個圖像代碼給下面 但我想匹配兩個圖像之間的兩列之間圖像匹配時我想顯示敬酒消息。就像第1列有玫瑰圖像匹配到第2列後,通過畫線後,如果兩列有相同的圖像顯示吐司消息。 如何匹配兩個圖像時,他們之間畫線
in MainActivity code :
RelativeLayout mRelativeLayout = (RelativeLayout)findViewById(R.id.linear);
mRelativeLayout.addView(new DrawView(this));
========================================= ======= 在drawView函數類:
public class DrawView extends View {
Paint paint = new Paint();
ArrayList<Line> lines = new ArrayList<Line>();
public DrawView(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
public DrawView(Context context, AttributeSet attrs) {
super(context, attrs);
paint.setAntiAlias(true);
paint.setStrokeWidth(6f);
paint.setColor(Color.BLACK);
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeJoin(Paint.Join.ROUND);
}
@Override
protected void onDraw(Canvas canvas) {
for (Line l : lines) {
canvas.drawLine(l.startX, l.startY, l.stopX, l.stopY, paint);
}
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
lines.add(new Line(event.getX(), event.getY()));
return true;
} else if ((event.getAction() == MotionEvent.ACTION_MOVE || event
.getAction() == MotionEvent.ACTION_UP) && lines.size() > 0) {
Line current = lines.get(lines.size() - 1);
current.stopX = event.getX();
current.stopY = event.getY();
invalidate();
return true;
} else {
return false;
}
}
}
========================== ===在線等級:
public class Line {
float startX, startY, stopX, stopY;
public Line(float startX, float startY, float stopX, float stopY) {
this.startX = startX;
this.startY = startY;
this.stopX = stopX;
this.stopY = stopY;
}
public Line(float startX, float startY) { // for convenience
this(startX, startY, startX, startY);
}
}