How do I reduce the line spacing between text in my Android layout?
Asked Answered
S

3

33

I'd like to decrease the line spacing between the text (User12, 5 movies, 2.5% improved) in the attached layout.

enter image description here

Here's the xml below (I tried removing the singleLine="true" statement and tried setting it to false):

<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="?android:attr/listPreferredItemHeight"
  android:orientation="horizontal" >

  <ImageView
    android:id="@+id/icon"
    android:src="@drawable/icon"
    android:layout_width="36dip"
    android:layout_height="36dip"
    android:layout_margin="5dip"
    android:scaleType="center"
    android:layout_gravity="center_vertical" />

   <LinearLayout
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_weight="7.5">
    <TextView
        android:id="@+id/scoreDesc"
        android:text="User12"
        android:layout_marginLeft="5dip"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textAppearance="@android:style/TextAppearance.Small"
        android:singleLine="true"
        android:ellipsize="marquee"
        android:layout_weight="1"
        android:layout_gravity="center_vertical" />
    <TextView
        android:id="@+id/scoreDesc"
        android:text="5 movies"
        android:layout_marginLeft="5dip"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textAppearance="@android:style/TextAppearance.Small"
        android:singleLine="true"
        android:ellipsize="marquee"
        android:layout_weight="1"
        android:layout_gravity="center_vertical" />

    <TextView
        android:id="@+id/scoreDesc"
        android:text="2.5% improved"
        android:layout_marginLeft="5dip"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textAppearance="@android:style/TextAppearance.Small"
        android:singleLine="true"
        android:ellipsize="marquee"
        android:layout_weight="1"
        android:layout_gravity="center_vertical" />
  </LinearLayout>
  <TextView
    android:id="@+id/scoreNum"
    android:text="32"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:gravity="center"
    android:textSize="20sp"
    android:textStyle="bold"
    android:paddingLeft="10dip"
    android:paddingRight="60dip"  
    />

</LinearLayout>
Schumacher answered 1/2, 2012 at 17:27 Comment(0)
R
76

Long time since the question was asked but if anyone needs an answer in the future this can be achieved simply by passing a negative value to

android:lineSpacingExtra="-4dp"
Rumen answered 19/11, 2012 at 23:48 Comment(3)
The question means between each component in the LinearLayout. This one works with just TextView. See my response below.Hunnish
Negative value cut down the below line characters like "g" will be cut down from bottom.Zygoma
It works and, from what I've seen, it doesn't cut lower parts of letters like "g" or "p".Michail
S
10

Setting lineSpacingMultiplier seems better in this case than lineSpacingExtra, e.g.

android:lineSpacingMultiplier="0.8"

(This works if all your text is in a single TextView that has the above line in the xml.)

Selfsealing answered 7/9, 2018 at 18:19 Comment(0)
H
7

As Cullan says above, you have to put a negative margin value:

android:layout_marginTop="-10dp"

<TextView
    android:id="@+id/scoreDesc"
    android:text="User12"
    android:layout_marginLeft="5dip"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textAppearance="@android:style/TextAppearance.Small"
    android:singleLine="true"
    android:ellipsize="marquee"
    android:layout_weight="1"
    android:layout_gravity="center_vertical" />
<TextView
    android:id="@+id/scoreDesc"
    android:text="5 movies"
    android:layout_marginLeft="5dip"
    android:layout_marginTop="-10dp"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textAppearance="@android:style/TextAppearance.Small"
    android:singleLine="true"
    android:ellipsize="marquee"
    android:layout_weight="1"
    android:layout_gravity="center_vertical" />

Hope this helps someone.

Hunnish answered 29/10, 2014 at 18:38 Comment(1)
This is the only solution that worked for me. None of the other ones worked.Waterhouse

© 2022 - 2024 — McMap. All rights reserved.