2013-04-10 86 views
2

我試圖做一個自定義的天文臺表 這裏是我的代碼,這是完全wrking 問題是STIC與是我想有內陰影獲取在內陰影的自定義視圖

公共類CustomChronometer擴展天文臺{

private boolean start = false; 
private long startTime, elapsedTime; 
private float angle = 0f; 
private Paint paint, p; 
private RectF r; 

public CustomChronometer(Context context, AttributeSet attrs) { 
    super(context, attrs); 
    paint = new Paint(); 
    paint.setColor(Color.parseColor("#0897ef")); 
    paint.setStrokeWidth(25); 

    paint.setStyle(Paint.Style.STROKE); 

    paint.setAntiAlias(true); 

//  paint.setStrokeCap(Cap.ROUND); 



} 

@SuppressLint("DrawAllocation") 
@Override 
protected void onLayout(boolean changed, int left, int top, int right, 
     int bottom) { 
    super.onLayout(changed, left, top, right, bottom); 
    r = new RectF(left + 30, top + 30, right - 30, bottom - 30); 
} 

@Override 
protected void onDraw(Canvas canvas) { 
    super.onDraw(canvas); 

    if (start) { 
     elapsedTime = System.currentTimeMillis(); 
     angle = (elapsedTime - startTime) * 0.006f; 
     canvas.drawArc(r, 270f, angle, false, paint); 
     if (angle >= 360) { 
      startTime = System.currentTimeMillis(); 
      angle = 0f; 
     } 
     invalidate(); 
    } 

} 

@Override 
public void start() { 
    super.start(); 
    start = true; 
    startTime = System.currentTimeMillis(); 
} 

@Override 
public void stop() { 
    super.stop(); 
    start = false; 
} 
} 

enter image description here

我需要它看起來像這樣

enter image description here

+0

你有沒有想出解決辦法?我試圖添加相同類型的陰影。 – drewhannay 2013-06-15 15:38:22

+0

是的,在塗料中試試這個\t \t paint.setColor(Color.parseColor(「#0897ef」)); \t \t paint.setStrokeWidth(40); \t \t paint.setStyle(Paint.Style.STROKE); \t \t paint.setAntiAlias(true); (新的BlurMaskFilter(7,Blur.INNER));也應該從清單中禁用硬件加速器 – Rohit 2013-06-17 15:16:57

+0

謝謝。你應該寫這個答案並接受它。 :) – drewhannay 2013-06-17 16:31:06

回答

3
paint paint.setColor(Color.parseColor("#0897ef")); 
paint.setStrokeWidth(40); 
paint.setStyle(Paint.Style.STROKE); 
paint.setAntiAlias(true); 
paint.setMaskFilter(new BlurMaskFilter(7, Blur.INNER)); 

也是硬件加速應該從清單被禁用 -

+0

爲什麼我要禁用「硬件加速」?沒有禁用可能嗎? – mars3142 2015-09-13 19:25:27