txt.setText("abc \n defgh");
I want to have line spacing to be some value. Sample range 5 dp.
abc
'5dp range'
defgh
txt.setText("abc \n defgh");
I want to have line spacing to be some value. Sample range 5 dp.
abc
'5dp range'
defgh
Take a look at android:lineSpacingExtra
(https://developer.android.com/reference/android/widget/TextView.html#attr_android:lineSpacingExtra) and android:lineSpacingMultiplier
(https://developer.android.com/reference/android/widget/TextView.html#attr_android:lineSpacingMultiplier).
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:lineSpacingExtra="5dp"
android:text="abc \n defgh"/>
I show you how to do this.
First: there are two ways for do it
Design (.xml) I'll separated these: (Full names) and (Years)
<TextView
android:id="@+id/notice_event"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="2"
android:text="Gustavo Tufiño Fernández \n 21 Years Old"/>
Nice solution, right?, but if you want do this dynamic, What would you do?
Class (Activity/Fragment/Adapters) Dynamic form
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// put values I need in String variables
String title = listNoticiasEventosFinal.get(0).getTitle();
String detail = listNoticiasEventosFinal.get(0).getDescription();
//Concat Strings with linespace and put int TextView
String final_text = title + System.getProperty ("line.separator") + detail;
TextView textView = (TextView) findViewById(R.id.notice_event);
textView.setText(final_text);
}
I hope I have help you, regards (Y)
**You can use "lineSpacingExtra". It will works, happy coding **
<TextView
android:layout_width="match_parent"
android:layout_height="180dp"
android:lineSpacingExtra="10dp"/>