Search code examples
androidandroid-5.0-lollipop

On android 5.0,if a textview has set lineSpacingExtra, and has only one line text, the textview doesn't show linespacing


It's different with other android version below 5.0! Demo code:

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:lineSpacingExtra="100dp"
    android:text="Hello World!"/>

On android 5.0, it shows: enter image description here

Below android 5.0, it shows: enter image description here

But if textview has more than two lines, they show the same! How can I do to make them show the same on different os version? Help!


Solution

  • you can set a paddingBottom to the view over Lollipop like

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:lineSpacingExtra="100dp"
        android:text="Hello World!"
        android:paddingBottom="@dimen/padding"/>
    

    and set padding=0dp in the dimens (values-v19) and set padding=100dp in the dimens (values-v21)