android textview padding between lines

2019-01-04 06:31发布

In my Android project, I've a TextView which displays a long text. I want to give some space between lines like we do in CSS with line-height property. How can we do this?

6条回答
SAY GOODBYE
2楼-- · 2019-01-04 07:09

If you want padding between text try LineSpacingExtra="10dp"

<TextView
        android:layout_width="match_parent"
        android:layout_height="180dp"
        android:lineSpacingExtra="10dp"/>
查看更多
神经病院院长
3楼-- · 2019-01-04 07:09

This supplemental answer shows the effect of changing the line spacing.

enter image description here

You can set the multiplier and/or extra spacing with

textView.setLineSpacing(float add, float mult)

Or you can get the values with

int lineHeight = textView.getLineHeight();
float add = tvSampleText.getLineSpacingExtra();          // API 16+
float mult = tvSampleText.getLineSpacingMultiplier();    // API 16+

where the formula is

lineHeight = fontMetricsLineHeight * mult + add

The default multiplier is 1 and the default extra spacing is 0.

查看更多
Deceive 欺骗
4楼-- · 2019-01-04 07:10

You can use TextView.setLineSpacing(n,m) function.

查看更多
闹够了就滚
5楼-- · 2019-01-04 07:14

Adding android:lineSpacingMultiplier="0.8" can make the line spacing to 80%.

查看更多
迷人小祖宗
6楼-- · 2019-01-04 07:22

you can look into android:lineSpacingExtra and apply it to your XML

Additional Info is on this page

or the related method public void setLineSpacing (float add, float mult)

Additional Info here

查看更多
迷人小祖宗
7楼-- · 2019-01-04 07:23

You can use lineSpacingExtra and lineSpacingMultiplier in your XML file.

查看更多
登录 后发表回答