Hector
Hector

Reputation: 5694

Android TextView Gravity BOTTOM unexpected behaviour

My current Android project has a requirement to display multiple lines of text (maximum of 3) within a TextView and place the text at the bottom of the text view.

My TextView is defined as follows:-

<TextView
    android:id="@+id/my_title"
    android:layout_width="@dimen/image_width"
    android:layout_height="@dimen/image_height"
    android:layout_alignTop="@+id/other_title"
    android:layout_marginTop="@dimen/span_eight"
    android:layout_toEndOf="@+id/dot"
    android:maxLines="3"
    android:gravity="bottom"
    android:padding="2dp"
    android:textColor="@android:color/white"
    android:textSize="@dimen/text_twelve" />

When the text to display is 3 or less lines the text displays as you would expect.

However when its longer than 3 lines the start of the text is truncated.

For example

"Artificial cells, nanomedicine, and biotechnology"

is displayed as

"`cine, and biotechnology`"

what I require is for it to display as

"`Artificial cells, nanom`"

How do I achieve the desired result?

Upvotes: 2

Views: 287

Answers (3)

Satish Ghuge
Satish Ghuge

Reputation: 71

Use:

android:ellipsize="end"

Add this property to your TextView you will see Text from start and at the end of third line 3 dots(...) will be there to indicate text is more than 3 lines.

Upvotes: 1

stalkerstacker
stalkerstacker

Reputation: 87

Try;

android:gravity="bottom|start"

Instead of

android:gravity="bottom"

Upvotes: 2

Charan
Charan

Reputation: 940

Use:

android:gravity="start"

bottom value in the gravity will change the display behavior. You vary the TextView height with margin.

Upvotes: 0

Related Questions