Как уменьшить межстрочный интервал между текстом в моем макете Android? - PullRequest
21 голосов
/ 01 февраля 2012

Я бы хотел уменьшить межстрочный интервал между текстом (пользователь 12, 5 фильмов, улучшение на 2,5%) в прикрепленном макете.

enter image description here

Вот XML ниже (я попытался удалить оператор singleLine = "true" и попытался установить его в 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>

Ответы [ 3 ]

60 голосов
/ 20 ноября 2012

Долгое время после того, как вопрос был задан, но если кому-то понадобится ответ в будущем, это можно сделать, просто передав отрицательное значение в

android:lineSpacingExtra="-4dp"
5 голосов
/ 29 октября 2014

Как говорит Каллан выше, вы должны поставить отрицательное значение поля:

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" />

Надеюсь, это кому-нибудь поможет.

2 голосов
/ 07 сентября 2018

Настройка lineSpacingMultiplier в этом случае выглядит лучше, чем lineSpacingExtra, например,

android:lineSpacingMultiplier="0.8"

(Это работает, если весь ваш текст находится в одном TextView, который имеет вышеуказанную строку в xml.)

...