package com.kiminonawa.mydiary.shared.gui; import android.annotation.TargetApi; import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Rect; import android.os.Build; import android.util.AttributeSet; import android.widget.ImageView; /** * Created by daxia on 2016/12/6. */ public class BoardImageView extends ImageView { private Rect rect; private Paint paint ; public BoardImageView(Context context) { super(context); init(context, null, 0); } public BoardImageView(Context context, AttributeSet attrs) { super(context, attrs); init(context, attrs, 0); } public BoardImageView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); init(context, attrs, 0); } @TargetApi(Build.VERSION_CODES.LOLLIPOP) public BoardImageView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); init(context, attrs, defStyleRes); } private void init(Context context, AttributeSet attrs, int defStyle) { rect = new Rect(); paint = new Paint(); } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.getClipBounds(rect); rect.bottom--; rect.right--; paint.setColor(Color.WHITE); paint.setStyle(Paint.Style.STROKE); paint.setStrokeWidth(3); canvas.drawRect(rect, paint); } }