2015-02-07 72 views
1

我有一个EditView类,允许用户在编辑模式下在屏幕上移动视图。另外,我在视图后面绘制一个矩形,以向用户显示视图区域。一切都按预期工作,但将绘制样式设置为STROKE会在移动视图时导致轨迹。如果我将风格保留为FILL,我没有这个问题。有没有解释呢?使用笔画风格时移动视图留下痕迹

CustomView类:

public class CustomView extends EditView { 

    public CustomView(Context context, AttributeSet attrs) { 
     super(context, attrs); 
    } 

    @Override 
    protected void onDraw(Canvas canvas) { 
     super.onDraw(canvas); 
     // Draw other stuff here 
    } 

    @Override 
    public boolean onTouchEvent(MotionEvent e) { 
     switch(e.getAction()) { 
      case MotionEvent.ACTION_MOVE: 
       if(!super.onTouchEvent(e)) 
        break; 
       // Code here 
      case MotionEvent.ACTION_UP: 
       if(!super.onTouchEvent(e)) 
        break; 
       // Code here 
      case MotionEvent.ACTION_DOWN: 
       if(!super.onTouchEvent(e)) 
        break; 
       // Code here 
     } 
     return true; 
    } 
} 

EditView中类:

public class EditView extends View { 

    private Paint p = new Paint(); 

    public EditView(Context context, AttributeSet attrs) { 
     super(context, attrs); 
     p.setStyle(Paint.Style.STROKE); 
    } 

    @Override 
    protected void onDraw(Canvas canvas) { 
     if(MainActivity.EDIT_MODE) 
      canvas.drawRect(0, 0, getMeasuredWidth(), getMeasuredHeight(), p); 
    } 

    public void setPaintColor(int color) { 
     p.setColor(color); 
    } 

    @Override 
    public boolean onTouchEvent(MotionEvent e) { 
     if(!MainActivity.EDIT_MODE) 
      return true; 
     RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) getLayoutParams(); 
     switch(e.getAction()) { 
      case MotionEvent.ACTION_MOVE: 
       // Change layout params here 
       return false; 
      case MotionEvent.ACTION_UP: 
       setPaintColor(Color.RED); 
       return false; 
      case MotionEvent.ACTION_DOWN: 
       setPaintColor(Color.GREEN); 
       return false; 
      default: return true; 
    } 
} 

回答

0

我设法解决这个问题:看来你必须设置描边宽度。