自定义控件之--继承控件(圆形TextView)
canvas.setDrawFilter(pfd);
canvas.drawCircle(getWidth()/2, getHeight()/2,Math.max(getWidth(), getHeight())/2, mBgPaint
);
package com.example.circletextview;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PaintFlagsDrawFilter;
import android.util.AttributeSet;
import android.widget.TextView;
public class CircleView extends TextView {
private Paint mBgPaint = new Paint();
PaintFlagsDrawFilter pfd = new PaintFlagsDrawFilter(0, Paint.ANTI_ALIAS_FLAG|Paint.FILTER_BITMAP_FLAG);
public CircleView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public CircleView(Context context, AttributeSet attrs) {
super(context, attrs);
mBgPaint.setColor(Color.WHITE);
mBgPaint.setAntiAlias(true);
}
public CircleView(Context context) {
super(context);
mBgPaint.setColor(Color.WHITE);
mBgPaint.setAntiAlias(true);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int measuredWidth = getMeasuredWidth();
int measuredHeight = getMeasuredHeight();
int max = Math.max(measuredWidth, measuredHeight);
setMeasuredDimension(max, max);
}
@Override
public void setBackgroundColor(int color) {
mBgPaint.setColor(color);
}
/**
* 设置通知个数显示
* @param text
*/
public void setNotifiText(int text){
setText(text+"");
}
@Override
public void draw(Canvas canvas) {
canvas.setDrawFilter(pfd);//给Canvas加上抗锯齿标志
canvas.drawCircle(getWidth()/2, getHeight()/2, Math.max(getWidth(), getHeight())/2, mBgPaint);
super.draw(canvas);
}
}
自定义控件之--继承控件(圆形TextView)的更多相关文章
- Android开发技巧——自定义控件之组合控件
Android开发技巧--自定义控件之组合控件 我准备在接下来一段时间,写一系列有关Android自定义控件的博客,包括如何进行各种自定义,并分享一下我所知道的其中的技巧,注意点等. 还是那句老话,尽 ...
- Android自定义控件之日历控件
标签: android 控件 日历 应用 需求 2015年09月26日 22:21:54 25062人阅读 评论(109) 收藏 举报 分类: Android自定义控件系列(7) 版权声明:转载注 ...
- C# 自定义控件VS用户控件
1 自定义控件与用户控件区别 WinForm中, 用户控件(User Control):继承自 UserControl,主要用于开发 Container 控件,Container控件可以添加其他Con ...
- 背水一战 Windows 10 (79) - 自定义控件: Layout 系统, 控件模板, 事件处理
[源码下载] 背水一战 Windows 10 (79) - 自定义控件: Layout 系统, 控件模板, 事件处理 作者:webabcd 介绍背水一战 Windows 10 之 控件(自定义控件) ...
- 自定义控件VS用户控件
自定义控件VS用户控件 2015-06-16 1 自定义控件与用户控件区别 WinForm中, 用户控件(User Control):继承自 UserControl,主要用于开发 Container ...
- Android零基础入门第17节:Android开发第一个控件,TextView属性和方法大全
原文:Android零基础入门第17节:Android开发第一个控件,TextView属性和方法大全 前面简单学习了一些Android UI的一些基础知识,那么接下来我们一起来详细学习Android的 ...
- Flutter学习笔记(38)--自定义控件之组合控件
如需转载,请注明出处:Flutter学习笔记(38)--自定义控件之组合控件 在开始之前想先写点其他的,emm...就是今天在学习到自定义控件的时候,由于自定义控件这块一直是我的短板,无论是Andro ...
- winform 自定义控件:半透明Loading控件
winform 自定义控件:半透明Loading控件 by wgscd date:2015-05-05 效果: using System;using System.Drawing;using Sys ...
- android 自定义空间 组合控件中 TextView 不支持drawableLeft属性
android 自定义空间 组合控件中 TextView 不支持drawableLeft属性.会报错Caused by: android.view.InflateException: Binary X ...
随机推荐
- centos redis 安装
# wget http://download.redis.io/releases/redis-2.8.6.tar.gz # tar xzf redis-2.8.6.tar.gz # cd redis- ...
- hadoop操作
常用命令: https://hadoop.apache.org/docs/r1.0.4/cn/hdfs_shell.html ls命令 /usr/bin/hadoop/software/hadoop/ ...
- keyboard添加down按钮
self.textView.inputAccessoryView = [self addToolbar]; - (UIToolbar *)addToolbar { UIToolbar *toolbar ...
- Http压测工具wrk使用指南【转】
用过了很多压测工具,却一直没找到中意的那款.最近试了wrk感觉不错,写下这份使用指南给自己备忘用,如果能帮到你,那也很好. 安装 wrk支持大多数类UNIX系统,不支持windows.需要操作系统支持 ...
- H264中的MapUnits
1 MapUnits 在FMO(Flexible Macroblock ordering)时,从宏块到条带组的映射是以MapUnits为基本单位,MapUnits可能为宏块,也可能是上下两个宏块(见下 ...
- maven GroupId 和ArtifactId的含义
GroupID是项目组织唯一的标识符,实际对应Java的包的结构,是main目录里java的目录结构. ArtifactID就是项目的唯一的标识符,实际对应项目的名称,就是项目根目录的名称.
- Python ---------copy
copy---探索 1.浅copy 就相当于把变量指针指向对象 相当于给对象从新起了个小名 a=[[1,2],3,4] a=[[1,2],3,4] b=a.copy() # print(a) # ...
- 使用PHP连接redis后,timeout连接太多的解决方案
这个问题,大家在使用php redis之后肯定都会遇到.所以本菜本着虚心求教的原则,又在网上四处求教.得到的答案,无非是以下两种: 1.redis没有主动close. 事后发现,这个答案纯属以讹传讹, ...
- URAL 6089 Nine
水题,找误差范围之内9最多的时间,如果有多个,选择误差最小的一个,如果还有多个,选择字典序最小的一个.同一个时间可以有不同的表示方法,例如60:15也可以表示为59:75. #include<s ...
- 统计C语言程序行数
补充前一篇中统计C语言程序行数的程序 写得比较匆忙,可能有些失误,等弄明白GitHub的用法并完善程序后再补充完整代码链接 没有写成函数,但经过简单修改可以作为一个计算或判断函数使用 判断算法主要为以 ...