有时候我们完全按照ui 布局写的代码 看到的效果却和ui的效果有一定的差距
有没有很苦恼的效果,最近帮同事改bug 发现了这个问题,很多地方都是他私自调节的
这个问题不可有啊,还是要按照ui的尺寸来,这种情况一般出现在字体的sp 比较大的情况
先看下的效果图
第一个和第三个明显文字的上下内间距很大,2和4 使用的属性为:android:includeFontPadding="false"
代码如下 ,这样设置以后可以取消一定的间距,但是不能完全消除内边距,这样设置以后基本都达到ui的要求
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/holo_red_dark"
android:text="中国"
android:gravity="center"
android:textColor="@android:color/black"
android:textSize="36sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:background="@android:color/holo_red_dark"
android:includeFontPadding="false"
android:lineSpacingMultiplier="0.9"
android:text="中国"
android:textColor="@android:color/black"
android:textSize="36sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:background="@android:color/holo_red_dark"
android:text="ping wwww.https"
android:textColor="@android:color/black"
android:textSize="36sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:includeFontPadding="false"
android:background="@android:color/holo_red_dark"
android:text="ping wwww.https"
android:textColor="@android:color/black"
android:textSize="36sp" />
如果是多行文字之间的距离 如果在设置android:includeFontPadding="false" 这个时候的效果是整体文字的上和下的距离了
文字和文字的上下距离就没有效果了,文字上下和左右的效果可以看下这边文章。
这里还是说下 看下面的图
最基本的TextView ,可以看到文字最上面和最下面有有一定内边距的设置android:includeFontPadding="false" 在看下效果
文字最上面和最下面的间距不是太明显了
我们可以看到android:includeFontPadding="false" 是设置文字内间距的,但是多行文字的时候不不在效果之内的,
文字的上下间距可以使用
lineSpacingExtra 和 lineSpacingMultiplier 和设置多行文字之间的距离
lineSpacingExtra 是设置具体的大小的
lineSpacingMultiplier 是设置倍数的
看着文字的间距10dp 左右我们先设置-10dp 看下效果
在设置一个android:lineSpacingMultiplier="0.8" 看下效果
差不多能挨着了,具体多少的大小看ui要求设置吧。