Search code examples
androidtextviewandroid-2.3-gingerbread

Android TextView won't show right number of lines in Android 2.3


I have a couple of TextViews in my app, which should have exactly 3 lines. This works on Android 3+, but on Android 2.3, which I'd also like to support, these fields have exactly 2 lines. I've also tried TextView.setLines(3); in code, but that does not seem to help. This is my TextView:

<TextView
    d1p1:lines="3"
    d1p1:maxLines="3"
    d1p1:minLines="3"
    d1p1:ellipsize="end"
    d1p1:text="Some Text"
    d1p1:textAppearance="?android:attr/textAppearanceMedium"
    d1p1:layout_width="fill_parent"
    d1p1:layout_height="55dp"
    d1p1:id="@+id/detailsTextView"
    d1p1:layout_below="@+id/locationTextView"
    d1p1:textSize="13dp"
    d1p1:textColor="@color/app_darkgray"
    d1p1:background="@color/app_dark_background"
    d1p1:layout_marginLeft="@dimen/sr_horizontal_padding"
    d1p1:layout_marginRight="@dimen/sr_horizontal_padding" />

Setting the height to wrap_content also does not work.


Solution

  • After some research it looks like my suspicion is correct. As discussed here (ellipsize multiline textview), Ellipsize causes issues with the min/max lines attributes. Because of this you may want to consider avoiding the Ellipsize otherwise, if that is not an option, you can follow the instructions in the other thread to use a custom TextView class to work around the problem.