skip to Main Content

How do you set a text leading on a TextView? Or how do you shift a text position relative to a view that it is in?

I want the height of the textview to be less than what wrap_content would set at default without cutting the text from the bottom.

I’ve tried using the layout_height tag on its xml layout but it would clip the text from the bottom just like the image I’ve provided on the link below, and I also have tried using the lineSpacingExtra tag but it seems to only work for the distance/leading between two lines.

Here is my xml file:

     <TextView
        android:layout_width="0dp"
        android:layout_height="30dp" 
        android:text="clipped text"/>

    <TextView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:lineSpacingExtra="-18dp"
        android:text="a text longer than usual to demonstrate line spacing"/>

Image for clarity: https://i.stack.imgur.com/QGV4B.png

2

Answers


  1. Why you can use wrap_content? Or can you share what are you trying to achieve?

    <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="clipped text"/>
    
    Login or Signup to reply.
  2. Did you try to do it using padding or paddingTop ? Try it with different values to get your desired result.

    <TextView
            android:layout_width="0dp"
            android:layout_height="30dp"
            android:paddingTop="0dp"
            android:text="clipped text"/>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search