34.标题换行居中的TextView
来源:互联网 发布:怎么玩转淘宝联盟 编辑:程序博客网 时间:2024/06/06 03:07
转载请注明出处 http://blog.csdn.net/qq_31715429/article/details/51373082
本文出自:猴菇先生的博客
在app中有一个展示数据的ListView,里面adapter中有标题和内容,标题居中显示。后来发现过长的标题在换行后会换行后靠左显示,不会居中。在网上找到了一个自定义TextView,可以实现换行后仍然集中显示:
package com.monkey.monkeymushroom.view;import android.content.Context;import android.graphics.Canvas;import android.graphics.Paint;import android.text.Layout.Alignment;import android.text.StaticLayout;import android.text.TextPaint;import android.util.AttributeSet;import android.widget.TextView;/** * 标题换行居中显示TextView */public class CenterTextView extends TextView { private StaticLayout myStaticLayout; private TextPaint tp; public CenterTextView(Context context, AttributeSet attrs) { super(context, attrs); } @Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); initView(); } private void initView() { tp = new TextPaint(Paint.ANTI_ALIAS_FLAG); tp.setTextSize(getTextSize()); tp.setColor(getCurrentTextColor()); myStaticLayout = new StaticLayout(getText(), tp, getWidth(), Alignment.ALIGN_CENTER, 1.0f, 0.0f, false); } @Override protected void onDraw(Canvas canvas) { myStaticLayout.draw(canvas); }}
0 0
- 34.标题换行居中的TextView
- 换行后居中显示的textview
- TextView换行居中,每行居中显示
- 自定义TextView超过一行换行居中
- textView换行的问题
- 关于TextView的内容居中和TextView控件居中
- TextView的自动换行问题
- AlertDialog标题居中的方法
- actionbar居中的view,标题
- Android标题居中的Toolbar
- textview的长度的不换行
- 简单的将TextView在LinearLayout居中
- 关于textview显示特殊符号居中的问题
- Android的TextView中的文字居中显示
- TextView的换行与行间距
- TextView首行缩进换行的问题
- 设置MSHFlexGrid控件的标题居中显示
- DataGridView列标题无法居中的问题
- 文章标题
- ANSI文档转成Unicode格式文档(超大文件也适用)
- Android 5.0 notification icon is blank square
- Oracle数据库-----常用sql语句和数据类型
- 交叉验证(简单交叉验证、k折交叉验证、留一法)
- 34.标题换行居中的TextView
- surfaceflinger中各个layer的排序
- kail2.0下hping3的安装和使用
- 如何通过进程pid获取进程名、可执行文件的名称
- Add One
- Spark-Caching /Checkpointing
- Eclipse 快捷键总结
- 随机采样和随机模拟:吉布斯采样Gibbs Sampling
- 安装lnmp脚本