7
我需要在視圖中顯示虛線圓圈。在Android視圖中繪製虛線圓圈
我需要在視圖中顯示虛線圓圈。在Android視圖中繪製虛線圓圈
嘗試這種解決方案:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(demoview);
}
private class DemoView extends View{
public DemoView(Context context){
super(context);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
Paint p = new Paint();
p.setColor(Color.RED);
DashPathEffect dashPath = new DashPathEffect(new float[]{5,5}, (float)1.0);
p.setPathEffect(dashPath);
p.setStyle(Style.STROKE);
canvas.drawCircle(100, 100, 50, p);
invalidate();
}
}
}
創建一個新的油漆和調用無效()中的每個的onDraw調用是一個壞主意! – LukaCiko 2015-01-19 14:12:05