How to programmatically display 5dp space in a TextView

I want to change the space of a TextView programmatically. I searched and I found setLineSpacing . The problem is that it receives two parameters, I tried so many values, but I could not get the result that I wanted. I just need to provide TextView 5dp text space, what should I put in the method to give it 5 dp linespace?

+5
source share
1 answer

Why can't you use setLineSpacing? This is exactly what I would use.

Based on Android Documentation :

public void setLineSpacing (float add, float mult)

Each row will have its height multiplied by mult and adding added to it.

So what you can do:

 myTextView.setLineSpacing(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5.0f, getResources().getDisplayMetrics()), 1.0f); 

Or you can change the XML layout of android:lineSpacingExtra . (See Documentation for Android .)

 <TextView android:id="@+id/txtview" android:layout_height="wrap_content" android:layout_width="fill_parent" android:lineSpacingExtra="5dp" /> 
+12
source

Source: https://habr.com/ru/post/1202520/


All Articles