如何减少 TextView 中有单个长文本的行之间的间距

How to reduce the spacing between the lines where there is a single long text in a TextView

我有一个 TextView,它有一个字符串,如快照所示,我怎样才能减少行间距。

快照

代码:

<TextView
                        android:id="@+id/txt_header"
                        android:layout_weight="1"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:gravity="left"
                        android:text="The swap request from KOMALJEET KAUR will time out in the next 3 hours, schedule pick up now."
                        android:lineSpacingExtra="-3dp"
                        android:lineSpacingMultiplier="0.5"
                        android:textColor="@color/clr_txt_header"
                        android:textSize="@dimen/text_small" />

您的方向是正确的,lineSpacingExtra 和 lineSpacingMultiplier 可以帮助您实现目标。注意 android:lineSpacingExtra="xdp" 其中 x 必须大于 1。lineSpacingMultiplier 是一个像您的用法一样的浮点数。 但是,您可以通过 TextView.setLineSpacing()

以编程方式设置它