您好,登錄后才能下訂單哦!
這篇文章主要講解了Android繪制發(fā)光效果的方法,內(nèi)容清晰明了,對(duì)此有興趣的小伙伴可以學(xué)習(xí)一下,相信大家閱讀完之后會(huì)有幫助。
前言
之前在看別人寫自定義view作繪制的時(shí)候,看到別人家的view自帶發(fā)光效果,看起來也是蠻炫酷的,于是自己也抽出時(shí)間來試用一下,這里做了一個(gè)模仿太陽的各種狀態(tài)樣式。
先上效果先上效果:
實(shí)現(xiàn)方式:
public BlurMaskFilter(float radius, Blur style) {
實(shí)現(xiàn)是使用的Paint類的setMaskFilter()方法,傳入BlurMaskFilter對(duì)象實(shí)現(xiàn)高斯模糊發(fā)光。
貼上代碼
public class MaskFilterView extends View { private Paint lightPaint; private int centerX, centerY; /** 發(fā)光范圍 */ private int radioRadius = 70; public MaskFilterView(Context context) { super(context); init(); } public MaskFilterView(Context context, @Nullable AttributeSet attrs) { super(context, attrs); init(); } private void init() { lightPaint = new Paint(); setLayerType(LAYER_TYPE_SOFTWARE, null); lightPaint.setColor(Color.parseColor("#EC3E3E")); lightPaint.setMaskFilter(new BlurMaskFilter(radioRadius, BlurMaskFilter.Blur.INNER)); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { centerX = getLeft() + getMeasuredWidth()/2; centerY = getTop() + getMeasuredHeight()/2; super.onMeasure(widthMeasureSpec, widthMeasureSpec); } public void setBlurType(int blurType) { switch (blurType) { case 0: lightPaint.setMaskFilter(new BlurMaskFilter(radioRadius, BlurMaskFilter.Blur.INNER)); break; case 1: lightPaint.setMaskFilter(new BlurMaskFilter(radioRadius, BlurMaskFilter.Blur.NORMAL)); break; case 2: lightPaint.setMaskFilter(new BlurMaskFilter(radioRadius, BlurMaskFilter.Blur.SOLID)); break; case 3: lightPaint.setMaskFilter(new BlurMaskFilter(radioRadius, BlurMaskFilter.Blur.OUTER)); break; } invalidate(); } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.drawCircle(centerX, centerY, 150, lightPaint); } }
看完上述內(nèi)容,是不是對(duì)Android繪制發(fā)光效果的方法有進(jìn)一步的了解,如果還想學(xué)習(xí)更多內(nèi)容,歡迎關(guān)注億速云行業(yè)資訊頻道。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。