当前位置:网站首页>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);
}
}
}
边栏推荐
- Analysis report on operation pattern and supply and demand situation of global and Chinese cyano ketoprofen industry from 2022 to 2028
- WordPress add photo album function [advanced custom fields Pro custom fields plug-in series tutorial]
- 【面试题】instancof和getClass()的区别
- Alternative to log4j
- 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
- Some examples of MgO operating database in go
- ∞ symbol line animation canvasjs special effect
- 从数字化过渡到智能制造
- Outer screen and widescreen wasted? Harmonyos folding screen design specification teaches you to use it
- 【排行榜】Carla leaderboard 排行榜 运行与参与手把手教学
猜你喜欢
技术分享| WVP+ZLMediaKit实现摄像头GB28181推流播放
5-minute NLP: summary of 3 pre training libraries for rapid realization of NER
canvas线条的动态效果
【面试题】什么是事务,什么是脏读、不可重复读、幻读,以及MySQL的几种事务隔离级别的应对方法
Dynamic effect of canvas lines
How to delete the entire row with duplicate items in a column of WPS table
第三代电力电子半导体:SiC MOSFET学习笔记(五)驱动电源调研
部门新来的00后真是卷王,工作没两年,跳槽到我们公司起薪18K都快接近我了
Collective example
JMeter socket connection sends data
随机推荐
信号完整性(SI)电源完整性(PI)学习笔记(一)信号完整性分析概论
Android SQLite database
What exactly is Nacos
【面试题】instancof和getClass()的区别
How to use promise Race() and promise any() ?
无人驾驶: 对多传感器融合的一些思考
OTT营销之风正盛,商家到底该怎么投?
5G dtu无线通信模块的电力应用
@mysql
信号完整性(SI)电源完整性(PI)学习笔记(二十五)差分对与差分阻抗(五)
∞ symbol line animation canvasjs special effect
不重要的token可以提前停止计算!英伟达提出自适应token的高效视觉Transformer网络A-ViT,提高模型的吞吐量!...
Adding, deleting, modifying and checking in low build code
canvas线条的动态效果
Global and Chinese tetrahydrofurfuryl butyrate industry operation pattern and future prospect report 2022 ~ 2028
浅析大型IM即时通讯系统开发难度
How does VR panorama make money? Based on the objective analysis of the market from two aspects
C program design topic 18-19 final exam exercise solutions (Part 2)
Tutorial details | how to edit and set the navigation function in the coolman system?
Discrete mathematics and its application detailed explanation of exercises in the final exam of spring and summer semester of 2018-2019 academic year