egorponomaryov
egorponomaryov

Reputation: 185

Applying lineHeight or lineSpacingExtra is not working

I have simple xml layout with TextView on it.

<TextView
            android:id="@+id/textView9"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="TextView1"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />
<TextView
            android:id="@+id/textView10"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="TextView2"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/textView9" />

I'm trying to apply lineSpacingExtra attribute to the second TextView. It makes no effect. Same with lineHeight.

Is there any mistake in my understanding of how these attributes work?

<TextView
            android:id="@+id/textView9"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:lineSpacingExtra="20sp"
            android:text="TextView1"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

<TextView
            android:id="@+id/textView10"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:lineSpacingExtra="20sp"
            android:text="TextView2"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/textView9" />

Upvotes: 0

Views: 1519

Answers (2)

use multiple line. use "dp" instead of "sp":

android:lineSpacingExtra="20dp"

Upvotes: 1

shmakova
shmakova

Reputation: 6426

From docs:

The value will not be applied for the last line of text.

So if you add multi-line text to the TextView (for example: TextView1\nTextView2), it will work.

Upvotes: 1

Related Questions