十年網(wǎng)站開發(fā)經(jīng)驗 + 多家企業(yè)客戶 + 靠譜的建站團隊
量身定制 + 運營維護+專業(yè)推廣+無憂售后,網(wǎng)站問題一站解決
本文實例為大家分享了Android空心圓及層疊效果的具體代碼,供大家參考,具體內(nèi)容如下
package com.bwei.test.zidingyiview2; import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.util.AttributeSet; import android.view.View; public class MyView extends View { private Context mcontext; private Paint mpaint; public MyView(Context context) { super(context); } public MyView(Context context, AttributeSet attrs) { super(context, attrs); } public MyView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); this.mcontext = context; } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); // 得到屏幕寬高 float wi = canvas.getWidth() / 2; float he = canvas.getHeight() / 2; // 創(chuàng)建第一個畫筆 Paint pa = new Paint(); // 上色 pa.setColor(Color.GREEN); // 顯示圓邊 pa.setAntiAlias(true); // 設置空心圓環(huán) pa.setStyle(Paint.Style.STROKE); // 設置圓環(huán)寬度 pa.setStrokeWidth(6); Paint pa2 = new Paint(); pa2.setColor(Color.BLUE); pa2.setAntiAlias(true); Paint pa3 = new Paint(); pa3.setColor(Color.BLACK); pa3.setAntiAlias(true); // 畫什么圓 canvas.drawCircle(wi-85, he-85, 80, pa2); canvas.drawCircle(wi, he, 100, pa); canvas.drawCircle(wi+110, he+110, 120, pa3); } }