最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android自定義View畫圓功能

 更新時(shí)間:2017年09月30日 09:14:56   作者:xcjean  
這篇文章主要為大家詳細(xì)介紹了Android自定義View實(shí)現(xiàn)畫圓功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

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

引入布局

<?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; 
 //構(gòu)造方法 
 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(); 
// 創(chuàng)建畫筆 
 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); 
 //設(shè)置圓環(huán)形狀和大小 
 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); 
 } 
} 

效果圖:

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • android讀取Assets圖片資源保存到SD卡實(shí)例

    android讀取Assets圖片資源保存到SD卡實(shí)例

    本文為大家詳細(xì)介紹下android讀取Assets圖片資源保存到SD卡的具體實(shí)現(xiàn),感興趣的各位可以參考下哈,希望對(duì)大家有所幫助
    2013-07-07
  • Android Studio4.0導(dǎo)入OpenCv4.3.0的方法步驟

    Android Studio4.0導(dǎo)入OpenCv4.3.0的方法步驟

    這篇文章主要介紹了Android Studio4.0導(dǎo)入OpenCv4.3.0的方法步驟,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-10-10
  • Android控件系列之Shape使用方法

    Android控件系列之Shape使用方法

    Android控件系列之Shape使用方法,需要的朋友可以參考一下
    2013-05-05
  • 簡(jiǎn)單實(shí)現(xiàn)Android鬧鐘程序 附源碼

    簡(jiǎn)單實(shí)現(xiàn)Android鬧鐘程序 附源碼

    這篇文章主要幫助大家簡(jiǎn)單實(shí)現(xiàn)Android鬧鐘程序,附源碼下載,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2016-07-07
  • Android實(shí)現(xiàn)日歷控件示例代碼

    Android實(shí)現(xiàn)日歷控件示例代碼

    本篇文章主要介紹了Android實(shí)現(xiàn)日歷控件示例代碼,實(shí)例講解了Android日期與時(shí)間相關(guān)控件的相關(guān)使用技巧,具有一定參考價(jià)值,需要的朋友可以參考下
    2017-03-03
  • Flutter實(shí)現(xiàn)頂部導(dǎo)航欄功能

    Flutter實(shí)現(xiàn)頂部導(dǎo)航欄功能

    這篇文章主要為大家詳細(xì)介紹了Flutter實(shí)現(xiàn)頂部導(dǎo)航欄功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-07-07
  • android播放器實(shí)現(xiàn)歌詞顯示功能

    android播放器實(shí)現(xiàn)歌詞顯示功能

    這篇文章主要為大家詳細(xì)介紹了android播放器實(shí)現(xiàn)歌詞顯示功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-11-11
  • Android開(kāi)發(fā)中ProgressDialog簡(jiǎn)單用法示例

    Android開(kāi)發(fā)中ProgressDialog簡(jiǎn)單用法示例

    這篇文章主要介紹了Android開(kāi)發(fā)中ProgressDialog簡(jiǎn)單用法,結(jié)合實(shí)例形式分析了Android使用ProgressDialog的進(jìn)度條顯示與關(guān)閉、更新等事件響應(yīng)相關(guān)操作技巧,需要的朋友可以參考下
    2017-10-10
  • Android使用Notification在狀態(tài)欄上顯示通知

    Android使用Notification在狀態(tài)欄上顯示通知

    這篇文章主要為大家詳細(xì)介紹了Android使用Notification在狀態(tài)欄上顯示通知,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-12-12
  • Android創(chuàng)建一個(gè)Activity的方法分析

    Android創(chuàng)建一個(gè)Activity的方法分析

    這篇文章主要介紹了Android創(chuàng)建一個(gè)Activity的方法,結(jié)合實(shí)例形式分析了Android創(chuàng)建Activity的具體步驟與相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下
    2016-04-04

最新評(píng)論

茂名市| 乌审旗| 台安县| 西和县| 新乡市| 衡南县| 武邑县| 盐池县| 涿鹿县| 新乐市| 彭阳县| 阿坝县| 昆明市| 广饶县| 宜丰县| 建昌县| 塘沽区| 洱源县| 五河县| 维西| 尉氏县| 吴桥县| 宜宾县| 双辽市| 榆林市| 连江县| 巴马| 灌云县| 雷州市| 太保市| 郑州市| 眉山市| 达日县| 舒兰市| 滁州市| 广昌县| 汕头市| 盐亭县| 河源市| 曲水县| 马山县|