自定义控件TextView

public class defineTextView extends TextView {
Context context;
public defineTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// TODO Auto-generated constructor stub
this.context=context;
}
public defineTextView(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
this.context=context;
}
public defineTextView(Context context) {
super(context);
this.context=context;
}
@Override
protected void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
Drawable[] drawable=getCompoundDrawables();
int drawablewidth=drawable[0].getIntrinsicWidth();
float textwidth=getPaint().measureText(getText().toString());
int drawablepadding=getCompoundDrawablePadding();
int bodywidth=(int) (drawablepadding+textwidth+drawablewidth);
canvas.translate((getWidth()-bodywidth)/2, 0);
canvas.drawLine(0, getHeight(), getWidth(), getHeight(), getPaint());
super.onDraw(canvas);
}
@Override
public void setTextSize(float size) {
super.setTextSize(size);
}
自定义控件TextView的更多相关文章
- 自定义控件 TextView 歌词 Lrc
演示 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> < ...
- Android 自定义控件-TextView
很多时候系统自带的View满足不了设计的要求,就需要自定义View控件.自定义View首先要实现一个继承自View的类.添加类的构造方法,override父类的方法,如onDraw,(onMeasur ...
- Android Toolbar 开发总结
初识 Toolbar Toolbar是在 Android 5.0 开始推出的一个 Material Design 风格的导航控件 ,Google 非常推荐大家使用 Toolbar 来作为Android ...
- Android M 控件:Snackbar、Toolbar、TabLayout、NavigationView
Snackbar Snackbar提供了一个介于Toast和AlertDialog之间轻量级控件,它可以很方便的提供消息的提示和动作反馈.Snackbar的使用与Toast的使用基本相同: Snack ...
- Android开发:最详细的 Toolbar 开发实践总结
最详细的 Toolbar 开发实践总结 过年前发了一篇介绍 Translucent System Bar 特性的文章 Translucent System Bar 的最佳实践,收到很多开发者的关注和反 ...
- Android ——Toolbar开发实践总结(转)
过年前发了一篇介绍 Translucent System Bar 特性的文章 Translucent System Bar 的最佳实践 ,收到很多开发者的关注和反馈.今天开始写第二篇,全面的介绍一下 ...
- Cooperation.GTST团队第二周项目总结
项目进展 这周我们把工作主要放在了UI界面的实现上,为了让整款APP看上去能够更加高大上,我们决定采用Android 5.0开始推出的一个Material Design风格的导航控件Toolbar. ...
- 最详细的 Android Toolbar 开发实践总结(转)
转自:http://www.codeceo.com/article/android-toolbar-develop.html 过年前发了一篇介绍 Translucent System Bar 特性的文 ...
- Android 手机卫士--自定义控件(获取焦点的TextView)
本文地址:http://www.cnblogs.com/wuyudong/p/5906735.html,转载请注明源地址. 本文将实现标题栏下面的textview中的文字跑马灯的效果,就是将一行文字水 ...
随机推荐
- Golang Clearing slice
//first method : slice = nil // second method : slice = slice[0:0] Source page : https://www.socketl ...
- Linux Kernel Version Numbering
Because there are numerous revisions and releases of the Linux kernel and new ones are developed at ...
- 图数据库(graph database)资料收集和解析 - daily
Motivation 图数据库中的高科技和高安全性中引用了一个关于图数据库(graph database)的应用前景的乐观估计: 预计到2017年,图数据库产业在数据库市场的份额将从2个百分点增长到2 ...
- RouteArea中AreaPrefix(Area 前缀)的使用
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...
- 正确使用List.toArray()(转)
在程序中,往往得到一个List, 程序要求对应赋值给一个array, 可以这样写程序: for example: Long [] l = new Long[list.size()]; for(in ...
- 论文笔记之:Deep Generative Image Models using a Laplacian Pyramid of Adversarial Networks
Deep Generative Image Models using a Laplacian Pyramid of Adversarial Networks NIPS 2015 摘要:本文提出一种 ...
- ECShop函数列表大全
lib_time.php gmtime() P: 获得当前格林威治时间的时间戳 /$0 server_timezone() P: 获得服务器的时区 /$0 local_mktime(hour=NULL ...
- Python学习笔记——Day1
突破从改变开始,一行行字符,熟悉的感觉,还是那个味儿...呀哈哈哈 一.变量 变量是计算机语言中能存储计算结果或能表示值的抽象概念,变量可以通过变量名访问.调用及修改.变量通常表示可变状态,即具有存储 ...
- 安全快速修改Mysql数据库名的5种方法
1. RENAME DATABASE db_name TO new_db_name这个..这个语法在mysql 5.1.7中被添加进来,到了5.1.23又去掉了.据说有可能丢失数据.还是不要用的好.详 ...
- Maven学习5-聚合与继承
一.聚合 如果我们想一次构建多个项目模块,那我们就需要对多个项目模块进行聚合 1.1.聚合配置代码 1 <modules> 2 <module>模块一</module&g ...