当前位置:网站首页>Paint rounded rectangle
Paint rounded rectangle
2022-06-25 00:21:00 【BY-91】
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.RectF;
import android.graphics.drawable.ColorDrawable;
import android.util.AttributeSet;
public class RoundRectLayout extends RelativeLayout {
private Path mPath;
private int mRadius;
private int mWidth;
private int mHeight;
private int mLastRadius;
public static final int MODE_NONE = 0;
public static final int MODE_ALL = 1;
public static final int MODE_LEFT = 2;
public static final int MODE_TOP = 3;
public static final int MODE_RIGHT = 4;
public static final int MODE_BOTTOM = 5;
private int mRoundMode = MODE_ALL;
private Paint mPaint;
public RoundRectLayout(Context context) {
super(context);
init();
}
public RoundRectLayout(Context context, AttributeSet attributeSet) {
super(context, attributeSet);
init();
}
public RoundRectLayout(Context context, AttributeSet attributeSet, int i) {
super(context, attributeSet, i);
init();
}
private void init(){
setBackgroundDrawable(new ColorDrawable(0x00000000));
mPath = new Path();
mPath.setFillType(Path.FillType.EVEN_ODD);
setCornerRadius(15);
mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mPaint.setStyle(Paint.Style.STROKE);
// mPaint.setStrokeWidth(4);
}
/**
* @param roundMode
*/
public void setRoundMode(int roundMode){
mRoundMode = roundMode;
}
/**
* @param radius
*/
public void setCornerRadius(int radius){
mRadius = radius;
}
private void checkPathChanged(){
if(getWidth() == mWidth && getHeight() == mHeight && mLastRadius == mRadius){
return;
}
mWidth = getWidth();
mHeight = getHeight();
mLastRadius = mRadius;
mPath.reset();
switch (mRoundMode){
case MODE_ALL:
mPath.addRoundRect(new RectF(0, 0, mWidth, mHeight), mRadius, mRadius, Path.Direction.CW);
break;
case MODE_LEFT:
mPath.addRoundRect(new RectF(0, 0, mWidth, mHeight),
new float[]{mRadius, mRadius, 0, 0, 0, 0, mRadius, mRadius},
Path.Direction.CW);
break;
case MODE_TOP:
mPath.addRoundRect(new RectF(0, 0, mWidth, mHeight),
new float[]{mRadius, mRadius, mRadius, mRadius, 0, 0, 0, 0},
Path.Direction.CW);
break;
case MODE_RIGHT:
mPath.addRoundRect(new RectF(0, 0, mWidth, mHeight),
new float[]{0, 0, mRadius, mRadius, mRadius, mRadius, 0, 0},
Path.Direction.CW);
break;
case MODE_BOTTOM:
mPath.addRoundRect(new RectF(0, 0, mWidth, mHeight),
new float[]{0, 0, 0, 0, mRadius, mRadius, mRadius, mRadius},
Path.Direction.CW);
break;
}
}
@Override
public void draw(Canvas canvas) {
if(mRoundMode != MODE_NONE){
// RectF mRectF = new RectF(0,0, mWidth,mHeight);
int saveCount = canvas.save();
checkPathChanged();
// mPaint.setColor(getContext().getColor(R.color.launcher_navi_widget_stroke_color));
// canvas.drawRoundRect(mRectF,16,16,mPaint);
canvas.clipPath(mPath);
super.draw(canvas);
canvas.restoreToCount(saveCount);
}else {
super.draw(canvas);
}
}
}
边栏推荐
- vim使用命令
- linux 系统redis常用命令
- 融合模型权限管理设计方案
- ArcGIS loads free online historical images as the base map (no plug-ins are required)
- Color gradient gradient color collection
- 为什么生命科学企业都在陆续上云?
- What is the difference between one way and two way ANOVA analysis, and how to use SPSS or prism for statistical analysis
- JMeter socket connection sends data
- svg线条动画背景js特效
- C program design topic 15-16 final exam exercise solutions (Part 1)
猜你喜欢

Color gradient gradient color collection

【面试题】什么是事务,什么是脏读、不可重复读、幻读,以及MySQL的几种事务隔离级别的应对方法

Hibernate learning 3 - custom SQL

Im instant messaging development application keeping alive process anti kill

Meta & Berkeley proposed a universal multi-scale visual transformer based on pooled self attention mechanism. The classification accuracy in Imagenet reached 88.8%! Open source

信号完整性(SI)电源完整性(PI)学习笔记(二十五)差分对与差分阻抗(五)

Discrete mathematics and its application detailed explanation of exercises in the final exam of spring and summer semester of 2018-2019 academic year

Do280openshift access control -- encryption and configmap

为什么生命科学企业都在陆续上云?

canvas螺旋样式的动画js特效
随机推荐
Hibernate learning 3 - custom SQL
UE4 WebBrowser图表不能显示问题
Human body transformation vs digital Avatar
im即时通讯开发应用保活之进程防杀
Outer screen and widescreen wasted? Harmonyos folding screen design specification teaches you to use it
2019 summary and 2020 outlook
【面试题】什么是事务,什么是脏读、不可重复读、幻读,以及MySQL的几种事务隔离级别的应对方法
Unmanned driving: Some Thoughts on multi-sensor fusion
A small program written this week
创意SVG环形时钟js特效
Dry and wet contacts
Common redis commands in Linux system
Current situation and development prospect forecast report of global and Chinese tetrahydrofurfuryl alcohol acetate industry from 2022 to 2028
D manual destruction may violate memory security
Current situation analysis and development trend prediction report of hesperidase industry in the world and China from 2022 to 2028
The drawableleft of the custom textview in kotlin is displayed in the center together with the text
ArcGIS loads free online historical images as the base map (no plug-ins are required)
Modstart: embrace new technologies and take the lead in supporting laravel 9.0
C程序设计专题 15-16年期末考试习题解答(上)
C program design topic 18-19 final exam exercise solutions (Part 2)