0

大家好 .. 在我的应用程序中,我已经成功在下面给出的两个图像代码之间画线,但是当图像匹配时我想匹配两列之间的两个图像我想显示一个敬酒消息。就像第 1 列有一个玫瑰图像它的匹配如果两列具有相同的图像,则通过画线到第 2 列,然后显示 toast 消息。 在此处输入图像描述

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);
}

}

4

1 回答 1

3

在Action_UP中的onTouchEvent方法中检查第二行的坐标,看看它们是否与所选图像匹配。如果它们匹配或介于图像范围之间,则在此处显示敬酒消息。

于 2013-10-16T13:04:38.747 回答