关于TextView 的属性

一、设置不同的字体和颜色值:
questionDesTextView=(TextView)findViewById(R.id.question_des); SpannableStringBuilder builder = new SpannableStringBuilder(questionDesTextView.getText().toString()); //ForegroundColorSpan 为文字前景色,BackgroundColorSpan为文字背景色 ForegroundColorSpan blackSpan = new ForegroundColorSpan(Color.BLACK); ForegroundColorSpan graySpan=new ForegroundColorSpan(Color.GRAY);
//第二个参数是开始的下标,第三个参数是结束的下标 builder.setSpan(blackSpan, 0,4, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); builder.setSpan(graySpan,4,9, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); questionDesTextView.setText(builder);

http://aichixihongshi.iteye.com/blog/1207503

二、设置字间距

字间距

textView有一个属性android:textScaleX是调节字间距的,它的值是一个float型。查看源代码,默认textView 此属性是使用的是:

android.internal.R.styleable.TextView_textScaleX

setTextScaleX(a.getFloat(attr, 1.0f));


 

行间距

Android系统中TextView默认显示中文时会比较紧凑,不是很美观。为了让每行保持一定的行间距,可以设置属性android:lineSpacingExtra或android:lineSpacingMultiplier。

关于Android下TextView中文换行问题,可查看Android自定义view-文本自动换行。

1、android:lineSpacingExtra
设置行间距,如”3dp”。

2、android:lineSpacingMultiplier
设置行间距的倍数,如”1.2″。

参考代码:

android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:lineSpacingExtra="3dp"
android:lineSpacingMultiplier="1.5"
android:textStyle="bold" />
posted @ 2017-06-01 10:17  张亚楠  阅读(371)  评论(0编辑  收藏  举报