RadioButton通常作为RadioGroup的子布局嵌套在里面,单独使用不太常用,本文实现RadioButton小红点、数字角标,主要是利用onDraw方法进行重写,绘制小红点、数字角标。如下:

工具类:
public class UIUtils {
public static int dp2px(float dpValue) {
final float scale = getContext().getResources().getDisplayMetrics().density;
return (int) (dpValue * scale + 0.5f);
}
}
实现代码:
public class AppRadioButton extends AppCompatRadioButton {
private Paint mPaint;
private boolean isShowDot;
private boolean isShowNumberDot;
//小红点半径
private final int circleDotRadius = UIUtils.dp2px(4);
//icon的尺寸,高 == 宽

本文介绍了一种自定义RadioButton的方法,通过重写onDraw方法来实现小红点和数字角标的显示。利用Canvas和Paint绘制圆点和数字角标,适用于RadioGroup中,提供了一个灵活的UI组件定制方案。
最低0.47元/天 解锁文章
6882

被折叠的 条评论
为什么被折叠?



