Android Canvas绘制丘比特之箭
生活随笔
收集整理的這篇文章主要介紹了
Android Canvas绘制丘比特之箭
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
畫心形
學(xué)習(xí)Android圖形繪制過程中,隨隨便便的作品。
隨便看看就好~~~
來張效果圖:
這里要說一下,為什么心周圍要描白邊呢,你猜~~
當(dāng)然是做這個啦
接下來就是箭了:
畫箭頭
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:實(shí)心 STROKE:空心arrowPath = new Path();} }箭Get:
丘比特之箭,咻~~~
組合后:
然并卵,里面有個問題(沒發(fā)現(xiàn)的請忽視),現(xiàn)在并沒有解決,啥時候想起來了,再議~
為什么這么做呢?當(dāng)然是逼死強(qiáng)迫癥啦~~
其實(shí),主要是還沒想好怎么解決(#斜眼)
總結(jié)
以上是生活随笔為你收集整理的Android Canvas绘制丘比特之箭的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 01 linux 下tcl源码编译安装和
- 下一篇: iOS 屏幕适配 iPhone X Sa