I have a TextView in my layout which is wrap_content in layout_width. It is limited to maximum of 15 characters so I\'m using maxLength.
I need to end this TextView
I gather (from comment) that @Yaniv already solved it using code - but this is the right way to do it (with xml). May help other users who land here. Trick is to use both toleftof and torightof.
<RelativeLayout>
...
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:singleLine="true"
android:layout_toRightOf="@id/some_element1"
android:layout_toLeftOf="@id/some_element2"/>
...
<RelativeLayout>
This will solve your problem, Use ellipsize
Property in your XML Code
android:ellipsize="end" <!-- This makes the magic ... thing -->
android:maxEms="15" <!-- Limit of the Text -->
android:singleLine="true" <!-- In case if you want everything in one line -->
Edit: singleLine
is deprecated. Use maxlines="1"
instead.
I needed to do this with Radio Button and I wanted to limit the size to one line. When I used Android:singleline="true"
, radio button's check circle disappeared. Here's the code that finally worked:
android:ellipsize="end"
android:maxLines="1"
There's no need to set ems. This will probably work also in TextView and other UI components. Hope this helps to someone.
Tried most of the solutions above. Using maxWidth was the key for me:
android:maxWidth="100dp"
android:maxLines="1"
android:ellipsize="end"
One of the easiest way is to add Right Padding + Ellipsize
<TextView
android:id="@+id/txtvw_contentcell_subhead"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Polem sampler, Lorem Ipsum golep tolem burop yemit noski"
android:ellipsize="end"
android:maxLines="1"
android:textColor="@color/caption_black_color"
android:textSize="@dimen/caption_size"
android:paddingRight="40dp"/>
Here is an example Subtitle Text with char limit.