我在互联网上没有回答这个问题,我试图用不同的颜色绘画,用户可以选择,问题是这个绘图视图没有绘制任何东西,我不知道如何广告触摸橡皮擦上仅擦除触摸点 这是自定义视图:
public class DrawView extends android.support.v7.widget.AppCompatImageView {
private ArrayList<ColouredPaths> mTouches;
// Current used colour
private int mCurrColour;
private Paint mPaint;
private boolean erase=false;
ColouredPaths mPath;
Canvas mCanvas;
public void setErase(boolean isErase){
//set erase true or false
erase=isErase;
}
public void setColor(int colour) {
mCurrColour = colour;
}
public DrawView(Context context) {
super(context);
init();
}
// XML constructor
public DrawView(Context context, AttributeSet attrs) {
super(context, attrs);
init(); }
private void init() {
mTouches = new ArrayList<>();
mPaint = new Paint();
mPaint.setColor(mCurrColour);
mPaint.setAntiAlias(true);
mPaint.setStrokeWidth(5);
mPaint.setStyle(Paint.Style.FILL);
mPaint.setStrokeJoin(Paint.Join.ROUND);
mPaint.setStrokeCap(Paint.Cap.ROUND);
}
private float mX, mY;
private static final float TOUCH_TOLERANCE = 4;
private void touch_start(float x, float y) {
mPath.reset();
mPath.moveTo(x, y);
mX = x;
mY = y;
}
private void touch_move(float x, float y) {
float dx = Math.abs(x - mX);
float dy = Math.abs(y - mY);
if (dx >= TOUCH_TOLERANCE || dy >= TOUCH_TOLERANCE) {
mPath.quadTo(mX, mY, (x + mX)/2, (y + mY)/2);
mX = x;
mY = y;
}
}
private void touch_up() {
mPath.lineTo(mX, mY);
mPath.reset();
// commit the path to our offscreen
mTouches.add(mPath);
// kill this so we don't double draw
mPath.reset();
}
@Override
public boolean onTouchEvent(MotionEvent event) {
float x = event.getX();
float y = event.getY();
mPath=new ColouredPaths(mCurrColour);
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
touch_start(x, y);
break;
case MotionEvent.ACTION_MOVE:
touch_move(x, y);
break;
case MotionEvent.ACTION_UP:
touch_up();
break;
}
return super.onTouchEvent(event);
}
@Override
protected void onDraw(Canvas c) {
// Let the image be drawn first
super.onDraw(c);
// Draw your custom points here
for (ColouredPaths p : mTouches) {
mPaint.setColor(p.colour);
c.drawPath(p,mPaint);}}
/**
* Class to store the coordinate and the colour of the point.
*/
private class ColouredPaths extends Path{
int colour;
public ColouredPaths( int colour) {
this.colour = colour;
}
}
}
如果有人能提供答案,我们将不胜感激 这是我的日志:
06-14 21:26:03.926 907-1410/? E/hwintelligencewifi: updataApInfo cellid =4190217533
06-14 21:26:03.926 907-1410/? E/hwintelligencewifi: addCurrentApInfo cellid =4190217533
06-14 21:26:03.928 907-1410/? E/hwintelligencewifi: addCurrentApInfo info is already there
06-14 21:26:03.932 907-1410/? E/hwintelligencewifi: inlineAddCurrentApInfo mInfos.size()=31
答案 0 :(得分:0)
您似乎永远不会在Drawview上实际设置OnTouchListener。