| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- package eVVM.apk.widget;
- import android.content.Context;
- import android.content.res.TypedArray;
- import android.graphics.Canvas;
- import android.graphics.Color;
- import android.graphics.Paint;
- import android.graphics.Path;
- import android.graphics.Rect;
- import android.graphics.RectF;
- import android.support.annotation.Nullable;
- import android.util.AttributeSet;
- import android.view.View;
- import android.widget.RelativeLayout;
- import eVVM.apk.R;
- /**
- * 头像的背景 不是RectLayout 只是个view
- */
- public class RoundHeadbgRectLayout extends View {
- private int mWidth;
- private int mHeight;
- /**
- * 弧形高度
- */
- private int mArcHeight;
- /**
- * 背景颜色
- */
- private int mBgColor;
- private Paint mPaint;
- private Context mContext;
- public RoundHeadbgRectLayout(Context context) {
- this(context, null);
- }
- public RoundHeadbgRectLayout(Context context, @Nullable AttributeSet attrs) {
- this(context, attrs, 0);
- }
- public RoundHeadbgRectLayout(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
- super(context, attrs, defStyleAttr);
- TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.ArcView);
- mArcHeight = typedArray.getDimensionPixelSize(R.styleable.ArcView_arcHeight, 0);
- mBgColor=typedArray.getColor(R.styleable.ArcView_bgColor, Color.parseColor("#303F9F"));
- mContext = context;
- mPaint = new Paint();
- }
- @Override
- protected void onDraw(Canvas canvas) {
- super.onDraw(canvas);
- mPaint.setStyle(Paint.Style.FILL);
- mPaint.setColor(mBgColor);
- Rect rect = new Rect(0, 0, mWidth, mHeight - mArcHeight);
- canvas.drawRect(rect, mPaint);
- Path path = new Path();
- path.moveTo(0, mHeight - mArcHeight);
- path.quadTo(mWidth / 2, mHeight, mWidth, mHeight - mArcHeight);
- mPaint.setAntiAlias(true);
- canvas.drawPath(path, mPaint);
- }
- @Override
- protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
- super.onMeasure(widthMeasureSpec, heightMeasureSpec);
- int widthSize = MeasureSpec.getSize(widthMeasureSpec);
- int widthMode = MeasureSpec.getMode(widthMeasureSpec);
- int heightSize = MeasureSpec.getSize(heightMeasureSpec);
- int heightMode = MeasureSpec.getMode(heightMeasureSpec);
- if (widthMode == MeasureSpec.EXACTLY) {
- mWidth = widthSize;
- }
- if (heightMode == MeasureSpec.EXACTLY) {
- mHeight = heightSize;
- }
- setMeasuredDimension(mWidth, mHeight);
- }
- }
|