自定义带红点的radioButton
来源:互联网 发布:腾达路由器网络不稳定 编辑:程序博客网 时间:2024/05/21 13:59
<com.ycx.driver.utils.widget.view.CustomRadioButton android:layout_width="200dp" android:layout_height="200dp" android:background="#00ffff" android:button="@null" android:padding="50dp" android:drawablePadding="10dp" android:text="个人" customRadioButton:drawableTop="@drawable/tab_profile_click" />
<declare-styleable name="CustomRadioButton"> <attr name="drawableTop" format="reference|color" /> </declare-styleable>
public class CustomRadioButton extends RadioButton { Paint paint = new Paint(); private int redius = 10; private Bitmap bitmap; private int bitmapWidth; private int bitmapHeight; public CustomRadioButton(Context context) { super(context); init(context, null); } public CustomRadioButton(Context context, AttributeSet attrs) { super(context, attrs); init(context, attrs); } public CustomRadioButton(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); init(context, attrs); } private void init(Context context, AttributeSet attrs) { paint = new Paint(); paint.setColor(Color.BLUE); paint.setStyle(Paint.Style.FILL); paint.setTextSize(getTextSize()); setGravity(Gravity.CENTER_HORIZONTAL); try { // Popup信息 bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.header_man); if (bitmap != null) { bitmapWidth = bitmap.getWidth(); bitmapHeight = bitmap.getHeight(); } } catch (Throwable e) { } } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); int widthMode = MeasureSpec.getMode(widthMeasureSpec); int widthSize = MeasureSpec.getSize(widthMeasureSpec); int heightMode = MeasureSpec.getMode(heightMeasureSpec); int heightSize = MeasureSpec.getSize(heightMeasureSpec); int width; int height; if (widthMode == MeasureSpec.EXACTLY) { width = widthSize + redius; } else { width = 200 + redius; } if (heightMode == MeasureSpec.EXACTLY) { height = heightSize + redius; } else { height = 200 + redius; } setMeasuredDimension(width, height); } @Override protected void onDraw(Canvas canvas) {// super.onDraw(canvas); int left = (getWidth() - bitmapWidth) / 2; int top = (getHeight() - bitmapHeight) / 2; int right = (getWidth() + bitmapWidth) / 2; int bottom = (getHeight() + bitmapHeight) / 2; if (left > 0 && top > 0 && bitmap != null) { canvas.drawBitmap(bitmap, left, top, null); } //绘制文字 float textWidth = paint.measureText(getText().toString()); canvas.drawText(getText().toString(), getWidth() / 2 - textWidth / 2, bottom +40, paint); paint.setColor(Color.RED); canvas.drawCircle(right, top, redius, paint); }
0 0
- 自定义带红点的radioButton
- Android RadioButton的自定义
- android自定义的RadioButton
- Android 自定义RadioButton的样式
- Android 自定义RadioButton的样式
- Android 自定义RadioButton的样式
- Android 自定义RadioButton的样式
- 自定义简单常用的RadioButton
- Android 自定义RadioButton的样式
- RadioButton与自定义RadioButton
- 自定义RadioButton
- 自定义Radiobutton
- 自定义radiobutton
- 自定义RadioButton
- RadioButton 自定义
- 自定义RadioButton
- 自定义RadioButton
- 自定义RadioButton
- 一个数组实现两个栈
- android学习—添加/删除module,xutils的添加
- Android Edittext 的 回车监听
- 三个在电脑上运行很有趣的程序
- html+css:按钮上显示消息数量精简代码
- 自定义带红点的radioButton
- ES5新特性—严格模式
- 将爱奇艺视频QSV格式转为MP4格式
- 【实用手记】使用sed命令替换指定文件内容
- Java网咯编程——第五章 URL和URI
- SSM整合
- 08、ES6 函数扩展
- 浏览器Cookie大小、个数限制
- 回归诊断