Android TextView SingleLine field hides long text

北城余情 提交于 2019-11-28 10:50:09
Jim

This is the purpose of "ellipsize" - truncating a portion of text to indicate additional text.

In you case, you may simply need to add something like:

android:ellipsize="end"

or you might need to go deeper:

Automatically ellipsize a string in Java

Or look at this:

android ellipsize multiline textview

The idea behind extending the class is that you can customize the behavior of the TextView when the text content exceeds the space provided. For example, you can give it the appearance the it "bleeds over" by removing padding, etc. An ellipsis is an indicator that is commonly used to explain "there's more text that you can't see" - this is how it would look:

This is really a really long...

(the 3 periods are the ellipsis - your text goes the opposite direction, but it should still work)

With a custom TextView, you could change the "..." to nothing or anything else you want (even an image, which I've done).

You could also marquee the text:

TextView Marquee not working

siddhartha shankar

Add 2 properties in xml

android:singleLine="true"

android:ellipsize="end"

You should play with ellipsize attribute of the TextView.Check below:

<TextView
    android:id="@+id/tempF"
    android:text="@string/tempF"
    android:layout_width="146dp"
    android:layout_height="wrap_content"
    android:textColor="#cccccc"
    android:textStyle="bold"
    android:textSize="92dp"
    android:fontFamily="serif"
    android:gravity="right"
    android:layout_marginTop="60dp"
    android:layout_gravity="top|left"
    android:singleLine="true"
    android:ellipsize="end"
    />
           <TextView
            android:id="@+id/tv_desc"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="@color/colorGray"
            android:textSize="@dimen/_18dp"
            android:padding="@dimen/_2dp"
            android:singleLine="true"
            android:ellipsize="end"
            android:text="@string/desc"/>
<View
    android:layout_width="match_parent"
    android:layout_height="1dp"
    android:background="#000000" />

It works.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!