国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

Android自定義View畫圓功能

2019-10-22 18:26:49
字體:
來源:轉載
供稿:網友

本文實例為大家分享了Android自定義View畫圓的具體代碼,供大家參考,具體內容如下

引入布局

<?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.bwie.test.xuejian1508a20170928.MainActivity">   <com.bwie.test.xuejian1508a20170928.ViView  android:layout_width="match_parent"  android:layout_height="match_parent"   /> </RelativeLayout>

自定義View的java類,繼承View

public class ViView extends View{  Paint paint;  Context context;  //構造方法  public ViView(Context context) {  super(context);  }   public ViView(Context context, AttributeSet attrs) {  super(context, attrs);  }   public ViView(Context context, AttributeSet attrs, int defStyleAttr) {  super(context, attrs, defStyleAttr);  }   public ViView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {  super(context, attrs, defStyleAttr, defStyleRes);  this.context=context;  }   @Override  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {  super.onMeasure(widthMeasureSpec, heightMeasureSpec);  }   @Override  protected void onLayout(boolean changed, int left, int top, int right, int bottom) {  super.onLayout(changed, left, top, right, bottom);   }   /*繪圖*/  @Override  protected void onDraw(Canvas canvas) {  super.onDraw(canvas);  //得到屏幕寬高  int width = getWidth();  int radius = width - 450/2;  int height = getHeight(); // 創建畫筆  Paint paint1 = new Paint();  Paint paint2 = new Paint();  Paint paint3= new Paint(); // 消除鋸齒  paint1.setAntiAlias(true);  paint2.setAntiAlias(true);  paint3.setAntiAlias(true);  //畫筆顏色  paint1.setColor(Color.RED);  paint2.setColor(Color.WHITE);  paint3.setColor(Color.BLUE); // 畫圓。確定位置 // canvas.drawRect(100,100,width/2,height/2,paint1); // canvas.drawCircle(100,100,100,paint1); // canvas.drawCircle(250,250,200,paint2); // canvas.drawCircle(500,500,300,paint3);  //設置圓環形狀和大小  RectF oval = new RectF(width-radius,width-radius,width+radius,width+radius);  paint1.setStrokeWidth(450);  canvas.drawArc(oval,-90,90,false,paint1);   canvas.drawCircle(width/2,height/2,450,paint1);  canvas.drawCircle(width/2,height/2,300,paint2);  canvas.drawCircle(width/2,height/2,200,paint3);  }   @Override  public boolean onTouchEvent(MotionEvent event) {  return super.onTouchEvent(event);  } } 

效果圖:

Android,View,畫圓

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VEVB武林網。


注:相關教程知識閱讀請移步到Android開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 福建省| 华蓥市| 万荣县| 平山县| 社会| 平阴县| 崇明县| 肇东市| 涪陵区| 巴塘县| 林州市| 海盐县| 诸城市| 五原县| 文山县| 清新县| 那坡县| 台中市| 定南县| 大邑县| 三江| 安徽省| 龙口市| 四会市| 凤庆县| 海口市| 湄潭县| 克拉玛依市| 曲周县| 韩城市| 卢氏县| 奉贤区| 保靖县| 平顺县| 淮滨县| 华容县| 博爱县| 丰城市| 兴安盟| 新田县| 康保县|