0

您会在图片中看到,左侧是法线,右侧是虚线。在我选择了虚线之后,法线变成了虚线。如果我尝试用法线绘画,它会将虚线转换为法线。

两条线

这是View我用来创建每一行的:

public void setDashLine(){

    dashedLine = true;
    paint = new Paint();
    paint.setPathEffect(dashEffect);
    paint.setStyle(Paint.Style.STROKE);
    paint.setAntiAlias(true);
            paint.setStrokeJoin(Paint.Join.ROUND);
            paint.setStrokeWidth(STROKE_WIDTH);
}

public void setNormalLine(){
    //paint.setColor(Color.BLACK);
    dashedLine = false;

    paint.setPathEffect(null);
    paint.setStyle(Paint.Style.STROKE);
    paint.setPathEffect(null);
    paint.setAntiAlias(true);
            paint.setStrokeJoin(Paint.Join.ROUND);
            paint.setStrokeWidth(STROKE_WIDTH);
}


protected void onDraw(Canvas canvas) {

    if(dashedLine){
        paint.setPathEffect(dashEffect);
    }
    else {
        paint.setPathEffect(null);
    }


final OnTouchListener drawLineListener = new OnTouchListener() {
    public boolean onTouch(View v, MotionEvent event) {

        FirstActivity.ll.setVisibility(LinearLayout.GONE);

        switch (event.getAction()) {
          case MotionEvent.ACTION_DOWN:
              myLine = new MyLine();
              myLine.xStart = event.getX();
              myLine.yStart = event.getY();

            return true;

          case MotionEvent.ACTION_MOVE:
          case MotionEvent.ACTION_UP:
            myLine.xEnd = event.getX();
            myLine.yEnd = event.getY();
            invalidate();
            lineList.add(myLine); 
            break;

          default:
            Log.d("mock it up", "Unknown touch event  " + event.toString());
            return false;
        }
        return true;

    }
};

final OnTouchListener drawDashedLineListener = new OnTouchListener() {
    public boolean onTouch(View v, MotionEvent event) {

        FirstActivity.ll.setVisibility(LinearLayout.GONE);

        switch (event.getAction()) {
          case MotionEvent.ACTION_DOWN:
             return true;

          case MotionEvent.ACTION_MOVE:
          case MotionEvent.ACTION_UP:

            break;

          default:
            Log.d("mock it up", "Unknown touch event  " + event.toString());
            return false;
        }
        return true;

    }
};
4

1 回答 1

0

你应该打电话给:paint = new Paint(); 在公共无效 setNormalLine() 中?

于 2013-03-22T01:21:44.673 回答