2011-06-08 133 views
25

我想提請像這樣
glow line
問題光暈效果行 - 我必須生成該行計劃在依賴用戶的交互(線的形式將在onTouchEvent產生 - ACTION_MOVE)。輝光動態生成線有效

我可以產生這種效果沒有XML文件或繪製premaid位圖?

回答

60

我模仿這種方式這樣的效果:

  1. BlurMaskFilter繪製線;
  2. 在其上畫法線。

我使用Path類生成行並保存座標爲MOVE_ACTION的事件,以僅生成我需要的部分路徑。

創建2 Paint() S:

_paintSimple = new Paint(); 
_paintSimple.setAntiAlias(true); 
_paintSimple.setDither(true); 
_paintSimple.setColor(Color.argb(248, 255, 255, 255)); 
_paintSimple.setStrokeWidth(20f); 
_paintSimple.setStyle(Paint.Style.STROKE); 
_paintSimple.setStrokeJoin(Paint.Join.ROUND); 
_paintSimple.setStrokeCap(Paint.Cap.ROUND); 

_paintBlur = new Paint(); 
_paintBlur.set(_paintSimple); 
_paintBlur.setColor(Color.argb(235, 74, 138, 255)); 
_paintBlur.setStrokeWidth(30f); 
_paintBlur.setMaskFilter(new BlurMaskFilter(15, BlurMaskFilter.Blur.NORMAL)); 

並繪製兩次我Path()

@Override 
protected void onDraw(Canvas canvas) { 
    canvas.drawPath(mPath, _paintBlur); 
    canvas.drawPath(mPath, _paintSimple); 
} 
+0

您能不能給更多的代碼? – pengwang 2011-06-12 08:37:12

+0

當然。編輯我的答案。 – sharl 2011-06-14 08:04:56

+0

什麼是** mPath ** ?? 我做了新的變種。同名 Path mPath = new Path(); 不改變! – Realbitt 2013-06-22 08:15:50