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);
}
}
}

beifencode的更多相关文章

随机推荐

  1. CentOS&.NET Core初试系列

    目的 对前段时间学习.NET Core的知识进行一次入门篇的总结,希望加深印象同时帮助刚学同学少走一些坑. 目录 CentOS的安装和网卡的配置 安装.NET Core SDK和发布网站 Nginx的 ...

  2. Java Web基础——Controller+Service +Dao三层的功能划分

    转自:https://www.cnblogs.com/cielosun/articles/5752272.html 1. Controller/Service/DAO简介: Controller是管理 ...

  3. 汇编语言_实验四_[bx]和loop的使用

    四.实验结论 1.       实验内容1 (1)源代码: assume cs:code code segment mov ax,0b800h mov ds,ax mov bx,07b8h mov c ...

  4. 如何去除内联元素(inline-block元素)之间的间距

    <body><a href="http://www.baidu.com">百度</a><a href="http://www.i ...

  5. ADT安装Genymotion的eclipse插件安装及错误解决办法

    接触安卓开发也有很长一段时间了,但是一直使用的真机测试程序,因为感觉android模拟器实在是太不方便,运行慢,而且经常出错.最近听人介绍说Genymotion这款Android模拟器相当不错,于是打 ...

  6. 案例19-页面使用ajax显示类别菜单

    1 版本一 版本只能在首页显示类别,当切换到了其它页面就不会显示 1 web层IndexServlet代码 package www.test.web.servlet; import java.io.I ...

  7. git学习笔记6

    打标签 git tag -m "Say bye-bye to all previous practice." old_practice //引号里是注释 本地删除不是真的删除,对暂 ...

  8. 纯CSS让overflow:auto页面滚动条出现时不跳动

    现代浏览器滚动条默认是overflow:auto类型的,也就是如果尺寸不足一屏,没有滚动条:超出,出现滚动条.于是,问题来了: 信息流页面,如新浪微博,是从上往下push渲染的.开始只有头部一些信息加 ...

  9. 《图解http协议》之HTTPs学习笔记

    对于IP协议,并不陌生.TP协议是TCP/IP协议簇中的核心协议,也是TCP/IP的载体.所有的TCP,UDP,ICMP及IGMP数据都以IP数据报格式传输.IP提供不可靠的,无连接的数据传送服务.I ...

  10. 关于重绘and重排

    在研究CSS3动画性能的时候,看到了重排两个字. 突然想到自己虽然听说过这么个东东,但一直也没深入研究之. 趁着当下正好有研究的劲头,所以一不做二不休,把这个point也给学习了. 同样是一番查找资料 ...