android:ellipsize in ICS text continues after ellipsis -


i have textview programmatically setting maxlines , setting android:ellipsize="end". works partially, reason text being truncated continues few characters after ellipsis in 4.2.2. actual text being truncated, not new characters.

it not working in 2.3.6 adds ellipsis each section line break or "\n".

i not using custom fonts, have seen has caused problems before.

here calculate , set maxlines:

final textview reviewview = (textview) view.findviewbyid(r.id.textviewposition3);  viewtreeobserver observer = reviewview.getviewtreeobserver(); observer.addongloballayoutlistener(new ongloballayoutlistener() {     @override     public void ongloballayout() {         int maxlines = (int) reviewview.getheight() / reviewview.getlineheight();         reviewview.setmaxlines(maxlines);         reviewview.setellipsize(truncateat.end);         reviewview.getviewtreeobserver().removeglobalonlayoutlistener(this);         //reviewview.getviewtreeobserver().removeongloballayoutlistener(this);     } }); 

here xml:

<?xml version="1.0" encoding="utf-8"?>   <relativelayout xmlns:android="http://schemas.android.com/apk/res/android"     android:id="@+id/fragmenttestlayout"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:orientation="vertical" >       <imageview          android:id="@+id/restaurantimage"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:adjustviewbounds="true"         android:src="@drawable/test"         android:layout_margintop="-10dp"         android:layout_marginright="20dp"         android:layout_marginleft="20dp"         />          <imageview          android:id="@+id/squareblack"         android:layout_alignright="@id/restaurantimage"         android:layout_aligntop="@id/restaurantimage"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:src="@drawable/square_black_small"         />         <textview         android:id="@+id/textviewposition"         android:layout_alignright="@id/squareblack"         android:layout_alignleft="@id/squareblack"         android:layout_alignbottom="@id/squareblack"         android:layout_aligntop="@id/squareblack"         android:layout_margin="1dp"         android:gravity="center"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:text="this test"         android:textsize="25sp"          android:textcolor="#a6cbff"         android:textstyle="bold"         />       <imageview          android:id="@+id/squareblue"         android:layout_toleftof="@id/squareblack"         android:layout_aligntop="@id/squareblack"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:src="@drawable/square_blue_small"         />        <textview         android:id="@+id/textviewposition1"         android:layout_alignright="@id/squareblue"         android:layout_alignleft="@id/squareblue"         android:layout_alignbottom="@id/squareblue"         android:layout_aligntop="@id/squareblue"         android:layout_margin="1dp"         android:gravity="center"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:text="7.5"         android:textsize="25sp"          android:textcolor="#902515"         android:textstyle="bold"         />       <textview         android:id="@+id/restaurantname"         android:layout_alignleft="@id/restaurantimage"         android:layout_alignbottom="@id/restaurantimage"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:text="restaurant name"         android:textsize="25sp"          android:textcolor="#fff"         android:textstyle="bold"         android:background="@drawable/greybar"         />       <textview         android:id="@+id/textviewposition2"         android:layout_below="@id/restaurantimage"         android:layout_centerhorizontal="true"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:text="february 15, 2013"         android:textcolor="#555"         android:textstyle="bold"         android:textsize="15sp"          />        <button android:id="@+id/readreview"         android:background="@drawable/readreview"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_alignparentbottom="true"         android:text="read review"          android:textcolor="#fff"         android:textcolorhighlight="#ccc"         android:textsize="15sp"         android:textstyle="bold"         android:layout_centerhorizontal="true"         />        <textview         android:id="@+id/textviewposition3"         android:layout_below="@id/textviewposition2"         android:layout_above="@id/readreview"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:textsize="15sp"         android:textcolorlink="#c90404"         android:layout_marginright="15dp"         android:layout_marginleft="15dp"         android:textcolor="#000"         />    </relativelayout> 

i solved programatically, i'm not sure it's best solution feels more of hack. seems working though.

        viewtreeobserver observer = reviewview.getviewtreeobserver();         observer.addongloballayoutlistener(new ongloballayoutlistener() {         @override         public void ongloballayout() {             int maxlines = (int) reviewview.getheight() / reviewview.getlineheight();              reviewview.getviewtreeobserver().removeglobalonlayoutlistener(this);               if(reviewview.getlinecount() > maxlines)             {                 int lineendindex = reviewview.getlayout().getlineend(maxlines - 1);                 string text = reviewview.gettext().subsequence(0, lineendindex-3) +" ...";                 reviewview.settext(text);             }         }     }); 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

keyboard - C++ GetAsyncKeyState alternative -

android - java.net.UnknownHostException(Unable to resolve host “URL”: No address associated with hostname) -