Android控件阴影圆角


import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.RectF;
import android.graphics.drawable.BitmapDrawable;
import android.os.Build;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;

public class CornersShadowLayout extends FrameLayout {

    private float[] radiusArray = new float[8];

    private Paint shadowPaint;//阴影画笔
    private RectF shadowRect;//阴影矩形的layer区域
    private Path shadowPath;//阴影矩形的路径
    private float shadowRadius = 0;//阴影半径
    private int shadowColor;//阴影颜色
    private float shadow_x = 0;//阴影偏移
    private float shadow_y = 0;//阴影偏移

    private Paint roundPaint;//裁剪圆角的画笔
    private RectF roundRect;//包含圆角矩形的路径的layer区域
    private Path roundPath;//圆角矩形的路径

    private float strokeWidth = 0;//边框宽度
    private Paint strokePaint;//边框画笔
    private int strokeColor;//边框颜色


    public CornersShadowLayout(@NonNull Context context) {
        this(context,null);
    }

    public CornersShadowLayout(@NonNull Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public CornersShadowLayout(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        //setLayerType(LAYER_TYPE_SOFTWARE, null);
        //四个边角的圆角半径
        float topLeftRadius = 0;
        float topRightRadius = 0;
        float bottomLeftRadius = 0;
        float bottomRightRadius = 0;
        if (attrs != null) {
            TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.CornersShadowLayout);
            float radius = ta.getDimension(R.styleable.CornersShadowLayout_radius, 0);
            topLeftRadius = ta.getDimension(R.styleable.CornersShadowLayout_topLeftRadius, radius);
            topRightRadius = ta.getDimension(R.styleable.CornersShadowLayout_topRightRadius, radius);
            bottomLeftRadius = ta.getDimension(R.styleable.CornersShadowLayout_bottomLeftRadius, radius);
            bottomRightRadius = ta.getDimension(R.styleable.CornersShadowLayout_bottomRightRadius, radius);
            strokeWid
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值