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

posted @ 2017-11-27 07:55  小毛驴  阅读(150)  评论(0编辑  收藏  举报