package com.minibox.mycpp.view;import android.content.Context;import android.graphics.Canvas;import android.graphics.Color;import android.graphics.Paint;import android.graphics.Path;import android.graphics.RectF;import android.util.AttributeSet;import android.view.MotionEvent;import android.view.View;import java.util.ArrayList;import java.util.List;import androidx.annotation.Nullable;/** * Created by lingbeijing on 2020/8/18. */public class RandomBoll extends View {         public RandomBoll(Context context) {             super(context);        init();    }    private Paint mPaint;    private Paint paintS;    private float touchX;    private float touchY;    private List<Path> multiPath = new ArrayList<>();    private Canvas myCanvas;    public RandomBoll(Context context, @Nullable AttributeSet attrs) {             super(context, attrs);        init();    }    public RandomBoll(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {             super(context, attrs, defStyleAttr);        init();    }    public RandomBoll(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {             super(context, attrs, defStyleAttr, defStyleRes);        init();    }    private void init(){             mPaint = new Paint();        mPaint.setARGB(0xff, 0x23, 0x23,0xad);        mPaint.setTextSize(59);        mPaint.setStyle(Paint.Style.STROKE);        mPaint.setAntiAlias(true);        mPaint.setStrokeWidth(1f);        paintS = new Paint(Paint.ANTI_ALIAS_FLAG);        paintS.setStyle(Paint.Style.STROKE);        paintS.setStrokeWidth(2f);        paintS.setColor(Color.BLUE);    }    @Override    public void draw(Canvas canvas) {             super.draw(canvas);        canvas.drawText("I Love You",200,60,mPaint);        RectF rect = new RectF(180, 10, 180 + 320, 80);        canvas.drawRoundRect(rect,51f,51f, paintS);        drawMultiPath(canvas);    }    Path pathNew;    @Override    public boolean onTouchEvent(MotionEvent event) {             touchX = event.getX();        touchY = event.getY();        if (event.getAction() == MotionEvent.ACTION_DOWN) {                 pathNew = new Path();            pathNew.reset();            pathNew.moveTo(touchX, touchY);            multiPath.add(pathNew);        }        if (Math.abs(touchX + touchY) > 20) {                 pathNew.lineTo(touchX, touchY);        }        invalidate();        return true;    }    private void drawMultiPath(Canvas c) {             if (c == null) {                 return;        }        for (Path p : multiPath)            c.drawPath(p, paintS);    }}

更多相关文章

  1. 代码中设置drawableleft
  2. android 3.0 隐藏 系统标题栏
  3. Android开发中activity切换动画的实现
  4. Android(安卓)学习 笔记_05. 文件下载
  5. Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
  6. 技术博客汇总
  7. android 2.3 wifi (一)
  8. AndRoid Notification的清空和修改
  9. Android中的Chronometer

随机推荐

  1. 新版Qt可以支持Android和IOS平台
  2. android下联网
  3. 【ArcGIS Android(安卓)10.2.9】5. WMSLa
  4. Android中的SQLite使用
  5. Android(安卓)PinnedSectionListView异常
  6. 8、RxJava+Retrofit+okhttp上传多张图片
  7. Android(安卓)在线升级APK
  8. android drawable setBounds()
  9. android: MapView加载多个 overlay 内存
  10. android录音实现