日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

Android Canvas绘制丘比特之箭

發布時間:2024/1/8 Android 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Android Canvas绘制丘比特之箭 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

畫心形

學習Android圖形繪制過程中,隨隨便便的作品。
隨便看看就好~~~

package com.zdl.gift.custom;import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.RectF; import android.support.annotation.Nullable; import android.util.AttributeSet; import android.view.View;/*** Created by zdl on 2017/8/30.*/public class Heart extends View {private Paint heartPaint;private RectF rectFTopLeft;private RectF rectFTopRight;private RectF rectFBottom;private int width;private int height;private Paint whitePaint1;private Paint whitePaint2;private RectF rectFLeft;private RectF rectFRight;public Heart(Context context) {super(context);}public Heart(Context context, @Nullable AttributeSet attrs) {super(context, attrs);init();}public Heart(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {super(context, attrs, defStyleAttr);init();}@Overrideprotected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {super.onMeasure(widthMeasureSpec, heightMeasureSpec);width = 3*getMeasuredWidth()/4;//取寬的3/4來繪制,讓旋轉圖形過后,心形能夠完全展示height = 3*getMeasuredHeight()/4;//取高的3/4來繪制,讓旋轉圖形過后,心形能夠完全展示}@Overrideprotected void onDraw(Canvas canvas) {super.onDraw(canvas);canvas.drawColor(Color.TRANSPARENT);//設置背景透明canvas.rotate(45, getMeasuredWidth()/2, getMeasuredHeight()/2);//旋轉45°,使心形變正rectFTopLeft.set(2, height/3+2, 2*width/3-2, height-2);//心形的左上部繪制位置rectFTopRight.set(width/3+2, 2, width-2, 2*height/3-2);//心形的右上部繪制位置rectFBottom.set(width/3, height/3, width-4, height-4);//心形的下部繪制位置rectFLeft.set(width/3, height-4, width, height);//心形左邊描邊位置rectFRight.set(width-4, height/3, width, height);//心形右邊描邊位置canvas.drawRect(rectFBottom, heartPaint);//心下部canvas.drawRect(rectFLeft, whitePaint2);//心下部左邊描邊canvas.drawRect(rectFRight, whitePaint2);//心下部右邊描邊/*先畫心的下部正方形,再畫心的左上角、右上角,是為了覆蓋正方形的左上角的點這里給心左上角、右上角描邊,修改起始角度和經過角度,是為了將上面正方形的左上角紅色覆蓋*/canvas.drawArc(rectFTopLeft, 90, 180, true, heartPaint);//心左上角canvas.drawArc(rectFTopLeft, 90, 185, false, whitePaint1);//心左上角描邊canvas.drawArc(rectFTopRight, 180, 180, true, heartPaint);//心右上角canvas.drawArc(rectFTopRight, 175, 186, false, whitePaint1);//心右上角描邊}private void init() {heartPaint = new Paint();//畫心的紅色畫筆heartPaint.setAntiAlias(true);//抗鋸齒heartPaint.setColor(Color.RED);whitePaint1 = new Paint();//給心形描邊的白色畫筆whitePaint1.setAntiAlias(true);whitePaint1.setColor(Color.WHITE);whitePaint1.setStrokeWidth(4.0f);//畫筆的寬度whitePaint1.setStyle(Paint.Style.STROKE);//FILL:實心 STROKE:空心whitePaint2 = new Paint();//給心形描邊的白色畫筆whitePaint2.setAntiAlias(true);whitePaint2.setColor(Color.WHITE);rectFTopLeft = new RectF();//心左上角位置rectFTopRight = new RectF();//心右上角位置rectFBottom = new RectF();//心下部位置rectFLeft = new RectF();//心下部左邊描邊位置rectFRight = new RectF();//心下部右邊描邊位置} }

來張效果圖:

這里要說一下,為什么心周圍要描白邊呢,你猜~~

當然是做這個啦

接下來就是箭了:

畫箭頭

package com.zdl.gift.custom;import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Path; import android.support.annotation.Nullable; import android.util.AttributeSet; import android.view.View;/*** Created by zdl on 2017/8/30.*/public class Arrow extends View {private int width;private int height;private Paint arrowPaint;private Path arrowPath;public Arrow(Context context) {super(context);}public Arrow(Context context, @Nullable AttributeSet attrs) {super(context, attrs);init();}public Arrow(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {super(context, attrs, defStyleAttr);init();}@Overrideprotected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {super.onMeasure(widthMeasureSpec, heightMeasureSpec);width = getMeasuredWidth();height = getMeasuredHeight();}@Overrideprotected void onDraw(Canvas canvas) {super.onDraw(canvas);canvas.drawColor(Color.TRANSPARENT);canvas.rotate(165, width/2, height/2);//箭頭主體arrowPath.moveTo(20, height/2-3);arrowPath.lineTo(width-30, height/2-3);arrowPath.lineTo(width-30, height/2-12);arrowPath.lineTo(width, height/2);arrowPath.lineTo(width-30, height/2+12);arrowPath.lineTo(width-30, height/2+3);arrowPath.lineTo(20, height/2+3);arrowPath.close();canvas.drawPath(arrowPath, arrowPaint);//上部尾翼for (int i = 0; i < 3; i++) {arrowPath.moveTo(20+20*i, height/2-3);arrowPath.lineTo(0+20*i, height/2-23);arrowPath.lineTo(12+20*i, height/2-23);arrowPath.lineTo(32+20*i, height/2-3);arrowPath.close();canvas.drawPath(arrowPath, arrowPaint);}//下部尾翼for (int i = 0; i < 3; i++) {arrowPath.moveTo(20+20*i, height/2+3);arrowPath.lineTo(0+20*i, height/2+23);arrowPath.lineTo(12+20*i, height/2+23);arrowPath.lineTo(32+20*i, height/2+3);arrowPath.close();canvas.drawPath(arrowPath, arrowPaint);}}private void init() {arrowPaint = new Paint();//箭頭的畫筆arrowPaint.setAntiAlias(true);//抗鋸齒arrowPaint.setColor(Color.parseColor("#33ffff"));arrowPaint.setStyle(Paint.Style.FILL);//FILL:實心 STROKE:空心arrowPath = new Path();} }

箭Get:

丘比特之箭,咻~~~

組合后:

然并卵,里面有個問題(沒發現的請忽視),現在并沒有解決,啥時候想起來了,再議~
為什么這么做呢?當然是逼死強迫癥啦~~
其實,主要是還沒想好怎么解決(#斜眼)

總結

以上是生活随笔為你收集整理的Android Canvas绘制丘比特之箭的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。