您好,登錄后才能下訂單哦!
本文實(shí)例為大家分享了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)建第一個(gè)畫(huà)筆 Paint pa = new Paint(); // 上色 pa.setColor(Color.GREEN); // 顯示圓邊 pa.setAntiAlias(true); // 設(shè)置空心圓環(huán) pa.setStyle(Paint.Style.STROKE); // 設(shè)置圓環(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); // 畫(huà)什么圓 canvas.drawCircle(wi-85, he-85, 80, pa2); canvas.drawCircle(wi, he, 100, pa); canvas.drawCircle(wi+110, he+110, 120, pa3); } }
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_main" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.bwei.test.zidingyiview2.MainActivity"> <com.bwei.test.zidingyiview2.MyView android:layout_width="wrap_content" android:layout_height="wrap_content"/> </RelativeLayout>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持億速云。
免責(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)容。