当前位置:网站首页>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);
}
}
}
边栏推荐
- 第三代电力电子半导体:SiC MOSFET学习笔记(五)驱动电源调研
- canvas线条的动态效果
- 信号完整性(SI)电源完整性(PI)学习笔记(二十五)差分对与差分阻抗(五)
- [interview question] the difference between instancof and getclass()
- Collective example
- Go crawler framework -colly actual combat (IV) -- Zhihu answer crawl (I)
- C程序设计专题 18-19年期末考试习题解答(下)
- 无需显示屏的VNC Viewer远程连接树莓派
- Human body transformation vs digital Avatar
- JDBC - database connection
猜你喜欢

时间统一系统

A small program written this week

U.S. House of Representatives: digital dollar will support the U.S. dollar as the global reserve currency

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

Related operations of ansible and Playbook

无需显示屏的VNC Viewer远程连接树莓派

Why do more and more physical stores use VR panorama? What are the advantages?

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
![[interview question] what is a transaction? What are dirty reads, unrepeatable reads, phantom reads, and how to deal with several transaction isolation levels of MySQL](/img/95/02a58c9dc97bd8347b43247e38357d.png)
[interview question] what is a transaction? What are dirty reads, unrepeatable reads, phantom reads, and how to deal with several transaction isolation levels of MySQL
How can I persuade leaders to use DDD to construct the liver project?
随机推荐
Scrollview height cannot fill full screen
Current situation and development prospect forecast report of global and Chinese tetrahydrofurfuryl alcohol acetate industry from 2022 to 2028
Hibernate learning 3 - custom SQL
Go crawler framework -colly actual combat (IV) -- Zhihu answer crawl (I)
软件测试与游戏测试文章合集录
Jar package merging using Apache ant
VIM use command
Zed acquisition
JPA learning 1 - overview, JPA, JPA core annotations, JPA core objects
[Solved] Public key for mysql-community-xxx. rpm is not installed
Go crawler framework -colly actual combat (4) -- Zhihu answer crawl (2) -- visual word cloud
D does not require opapply() as a domain
Collective例子
Report on operation mode and future development trend of global and Chinese propenyl isovalerate industry from 2022 to 2028
Eye gaze estimation using webcam
@mysql
JDBC —— 数据库连接
信号完整性(SI)电源完整性(PI)学习笔记(一)信号完整性分析概论
Ansible及playbook的相关操作
Difficult and miscellaneous problems: A Study on the phenomenon of text fuzziness caused by transform