Android Textview ellipsize with multiple rows -
i trying ellips @ end of textview has multiple lines of text. "..." showing @ last space in text , other followed other characters. how make sure "..." @ end.
see example image
the xml layout file :
<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:tools="http://schemas.android.com/tools" xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginright="5dp" android:orientation="horizontal" > <textview android:id="@+id/nfdatemonth" android:layout_width="64dp" android:layout_height="wrap_content" android:layout_marginleft="10dp" android:layout_marginright="8dp" android:layout_margintop="2dp" android:background="@drawable/topsegment" android:gravity="center" android:text="apr" android:textallcaps="true" android:textcolor="#f2e606" android:textsize="22sp" android:textstyle="bold" /> <textview android:id="@+id/nfdatedate" android:layout_width="64dp" android:layout_height="wrap_content" android:layout_below="@+id/nfdatemonth" android:layout_marginbottom="10dp" android:layout_marginleft="10dp" android:layout_marginright="8dp" android:background="@drawable/bottomsegment" android:gravity="center" android:text="28" android:textsize="22sp" /> <textview android:id="@+id/nftitle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginbottom="2dp" android:layout_margintop="0dp" android:layout_torightof="@+id/nfdatemonth" android:text="half marathon" android:textappearance="?android:attr/textappearancemedium" android:textsize="16sp" /> <textview android:id="@+id/nfcontent" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/nftitle" android:layout_gravity="left" android:layout_marginbottom="2dp" android:layout_marginright="16dp" android:layout_margintop="2dp" android:layout_torightof="@+id/nfdatedate" android:ellipsize="end" android:maxlines="2" android:text="content\nline 2 line 3 sadsa dsd dsa dsd big big big sd sad sad sadsadsad asd sad d asd das das das das da sd asd asd 1 2 3 4 5 sixx seven" android:textappearance="?android:attr/textappearancemedium" android:textsize="12sp" /> </relativelayout>
i had same issue today. it's bug in textview or textutils (method ellipsize). in case it's caused text new lines.
there 2 solutions:
- get first line only:
string longtext = "..."; string body = new scanner(longtext).nextline(); textview.settext(body);
2. remove new lines in text
string longtext = "..."; string body = longtext.replace("\n", "").replace("\r", ""); textview.settext(body);
Comments
Post a Comment