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
Android控件阴影圆角
最新推荐文章于 2023-05-05 16:19:08 发布
本文探讨了如何在Android应用中为控件添加阴影和圆角效果。通过自定义 attrs.xml 文件来定义样式属性,然后在布局中应用这些属性,可以实现灵活的UI设计,提升用户体验。
摘要由CSDN通过智能技术生成