问题
- 为什么TextView默认上下留空?
- 设置includeFontPadding参数,是否有效去除上下留空?
includeFontPadding参数比较图
源码分析(展示重点方法)
先看TextView计算过程:
protected
void onMeasure(
int widthMeasureSpec,
int heightMeasureSpec) {
int heightMode = MeasureSpec .getMode(heightMeasureSpec);
int heightSize = MeasureSpec .getSize(heightMeasureSpec);
int height;
//计算宽度代码省略
if (heightMode == MeasureSpec .EXACTLY) {
//准确设置高度
} else {
int heightMode = MeasureSpec .getMode(heightMeasureSpec);
int heightSize = MeasureSpec .getSize(heightMeasureSpec);
int height;
//计算宽度代码省略
if (heightMode == MeasureSpec .EXACTLY) {
//准确设置高度
} else {