zoukankan      html  css  js  c++  java
  • beifencode

    package com.hesheng.myapplication;

    import android.content.Context;
    import android.graphics.Bitmap;
    import android.graphics.BitmapFactory;
    import android.graphics.Canvas;
    import android.graphics.Color;
    import android.graphics.Paint;
    import android.util.AttributeSet;
    import android.widget.ImageView;

    /**
    * Created by wangchaomac on 2017/11/27.
    */
    public class CenterImage extends ImageView {
    private Paint paint;
    private boolean isCenterImgShow;
    private Bitmap bitmap;
    public void setCenterImgShow(boolean centerImgShow) {
    isCenterImgShow = centerImgShow;
    if (isCenterImgShow) {
    bitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);
    invalidate();
    }
    }
    public CenterImage(Context context) {
    super(context);
    init();
    }
    public CenterImage(Context context, AttributeSet attrs) {
    super(context, attrs);
    init();
    }
    public CenterImage(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    init();
    }
    private void init() {
    paint = new Paint();
    }
    private boolean isInit = false;
    @Override
    protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    if ( bitmap != null) {


    Paint paint2 = new Paint();
    paint2.setStyle(Paint.Style.FILL);
    paint2.setColor(Color.RED);
    canvas.drawCircle( getMeasuredWidth()/2 , 20 ,10, paint2);
    canvas.drawBitmap(bitmap, getMeasuredWidth() / 2 - bitmap.getWidth() / 2, getMeasuredHeight() / 2 - bitmap.getHeight() / 2, paint);
    Paint paint3 = new Paint();
    paint3.setStyle(Paint.Style.FILL);
    paint3.setColor(Color.BLACK);
    if(isInit){
    canvas.drawCircle( getMeasuredWidth()/2+50, getMeasuredHeight()-20 ,10, paint3);
    isInit = false;
    return;
    }

    canvas.drawCircle( getMeasuredWidth()/2 , getMeasuredHeight()-20,10, paint3);
    }
    }
    }

  • 相关阅读:
    TVM性能评估分析(三)
    TVM性能评估分析(二)
    TVM性能评估分析(一)
    飞腾上实体名单?
    华为不造车,广汽合作智能驾驶
    异构计算编程
    服务器硬件层次架构
    为何说要多用组合少用继承?如何决定该用组合还是继承?
    极客时间学习
    如果学不好编程,就看看这个吧
  • 原文地址:https://www.cnblogs.com/wcLT/p/7902512.html
Copyright © 2011-2022 走看看