AndyZOny AndyZOny -4 years ago 106
Android Question

How to limit text Views with dots "...."

I just have create a view like this as I marked in enter image description here
this view contains a Relative layout in this relative layout there's a texts and Image the problem is when I have a long text it goes up on the image all I need I want to limit this text as to not go on the other view that I want to complete with dots "...." like this enter image description here
this is the part I want to edit .xml

<RelativeLayout
android:id="@+id/rl2"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/line3"
android:background="#FFFFFF">

<RelativeLayout
android:id="@+id/removeBtn"
android:layout_width="90dp"
android:layout_height="40dp"
android:layout_alignParentEnd="true"
android:onClick="remove"
android:layout_alignParentRight="true"
android:layout_below="@+id/membersLv"
android:background="#E93232">


<TextView
android:id="@+id/textView8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="remove"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="Remove"
android:textColor="#ffffff" />
</RelativeLayout>

<ImageView
android:id="@+id/joinedIcon"
android:layout_width="wrap_content"
android:layout_height="25dp"
android:layout_centerVertical="true"
android:layout_marginEnd="0dp"
android:layout_marginRight="10dp"
android:layout_toLeftOf="@+id/joinedTV"
android:layout_toStartOf="@+id/joinedTV"
app:srcCompat="@drawable/joinedicon" />

<TextView
android:id="@+id/joinedTV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginEnd="71dp"
android:layout_marginRight="71dp"
android:layout_toLeftOf="@+id/removeBtn"
android:layout_toStartOf="@+id/removeBtn"
android:text="Joined"
android:textColor="#3DA530" />

<TextView
android:id="@+id/memberName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignTop="@+id/joinedTV"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
android:text="Mahmoud"
android:textColor="#5F5F5E" />
</RelativeLayout>


the text I want to solve it with id "memberName"
Sorry for my bad English and Sorry If any thing is not clear

Answer Source

You can set option for Textview length

android:maxLength="12"

or

android:ellipsize="end"
android:maxLines="1"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download