2015-02-07 73 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

我設法解決這個問題:看來你必須設置描邊寬度。