Android 代码画角标 offcutView
效果如下:
代码:
<com.andye.OffcutView android:layout_width="30dp" android:layout_height="30dp"/>
public class OffcutView extends View { private String Text =""; // private int textSize = 22; private int radius=6; public ChampionShipOffcutView(Context context) { super(context); } public ChampionShipOffcutView(Context context, AttributeSet attrs) { super(context, attrs); } public ChampionShipOffcutView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } @SuppressLint("DrawAllocation") protected void onDraw(Canvas canvas) { if(Text==null) { return; } int w = getWidth(), h = getHeight(); Paint paint = new Paint(); paint.setAntiAlias(true); paint.setStyle(Paint.Style.FILL); paint.setColor(Color.argb(255, 69, 112, 234)); canvas.drawCircle(radius, radius, radius, paint); Path path = new Path(); path.moveTo(radius, 0); path.lineTo( w, 0); path.lineTo(0, h); path.lineTo(0, radius); path.close(); canvas.drawPath(path, paint); canvas.save(); TextPaint textPaint = new TextPaint(); textPaint.setColor(Color.argb(255, 255, 255, 255)); textPaint.setAntiAlias(true); textPaint.setTextSize(w/4); float x,y; y=w*0.707f; y=(y*8)/10; x=(float) (-textPaint.measureText(Text))/2; canvas.rotate(-45); canvas.drawText(Text, x , y, textPaint); canvas.restore(); } public void setText(String str) { Text = str==null?"":str; invalidate(); } }
如果,这篇博客帮您解决了问题,不妨点击一下右下角的【推荐】。如果,您希望更容易地发现我的新博客,不妨点击一下【加关注】。因为,我的热情需要您的肯定和支持!感谢您的阅读,如果文章中有错误或者您有什么好的建议,也欢迎您直接留言批评指教。Thanks,friends! |
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步