drawableleft与文本一起居中显示
来源:互联网 发布:java常用api总结 编辑:程序博客网 时间:2024/05/16 06:45
/**
* drawableLeft与文本一起居中显示
*
*/
public class DrawableCenterTextView extends TextView {
public DrawableCenterTextView(Context context, AttributeSet attrs,
int defStyle) {
super(context, attrs, defStyle);
}
public DrawableCenterTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public DrawableCenterTextView(Context context) {
super(context);
}
@Override
protected void onDraw(Canvas canvas) {
Drawable[] drawables = getCompoundDrawables();
if (drawables != null) {
Drawable drawableLeft = drawables[0];
if (drawableLeft != null) {
float textWidth = getPaint().measureText(getText().toString());
int drawablePadding = getCompoundDrawablePadding();
int drawableWidth = 0;
drawableWidth = drawableLeft.getIntrinsicWidth();
float bodyWidth = textWidth + drawableWidth + drawablePadding;
canvas.translate((getWidth() - bodyWidth) / 2, 0);
}
}
super.onDraw(canvas);
}
}
* drawableLeft与文本一起居中显示
*
*/
public class DrawableCenterTextView extends TextView {
public DrawableCenterTextView(Context context, AttributeSet attrs,
int defStyle) {
super(context, attrs, defStyle);
}
public DrawableCenterTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public DrawableCenterTextView(Context context) {
super(context);
}
@Override
protected void onDraw(Canvas canvas) {
Drawable[] drawables = getCompoundDrawables();
if (drawables != null) {
Drawable drawableLeft = drawables[0];
if (drawableLeft != null) {
float textWidth = getPaint().measureText(getText().toString());
int drawablePadding = getCompoundDrawablePadding();
int drawableWidth = 0;
drawableWidth = drawableLeft.getIntrinsicWidth();
float bodyWidth = textWidth + drawableWidth + drawablePadding;
canvas.translate((getWidth() - bodyWidth) / 2, 0);
}
}
super.onDraw(canvas);
}
}
0 0
- drawableleft与文本一起居中显示
- drawableLeft与文本一起居中显示
- TextView的drawableLeft与文本一起居中显示(以及代码设置drawableLeft)
- 【Android】自定义控件让TextView的drawableLeft与文本一起居中显示
- 自定义控件让TextView、Button的drawableLeft和drawableRight与文本一起居中显示
- 自定义控件让TextView的drawableLeft与文本一起居中显示
- 【Android】自定义控件让TextView的drawableLeft与文本一起居中显示
- 自定义控件让TextView的drawableLeft与文本一起居中显示
- 自定义控件让TextView的drawableLeft与文本一起居中显示
- 【Android】自定义控件让TextView的drawableLeft与文本一起居中显示
- 【Android】自定义控件让TextView的drawableLeft与文本一起居中显示
- 自定义控件让TextView的drawableLeft与文本一起居中显示
- 自定义控件让TextView(Radiobutton)、Button的drawableLeft和drawableRight与文本一起居中显示
- 自定义控件让TextView的drawableLeft与文本一起居中显示
- 自定义控件让TextView的drawableLeft与文本一起居中显示
- 【Android】自定义控件让TextView的drawableLeft与文本一起居中显示
- TextView、Button的drawableLeft和drawableRight与文本一起居中显示
- 自定义控件让EditText的drawableLeft与文本一起居中显示
- 最小圈
- NOIP2012 开车旅行 [Splay] [ST倍增]
- 单元测试框架-Junit介绍
- HDU 1556 | Color the Ball —— 树状数组
- 约瑟夫问题(Josephus Problem)
- drawableleft与文本一起居中显示
- [原创]`Constructor` has no propType for native prop `RCTView.maxHeight` of native type
- js中函数参数值传递和引用传递
- 自己动手写工具包——目录扫描器
- 语义性与元素名全称问题
- FreeCMS视频教程 敏感词管理
- Application——基本知识
- 揭秘315黑客wifi,如何保障APP数据安全
- 嵌入式复习12