Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display three dots at the end of the textview

In right side I used textview to display selected timezone, if user select it then alert dialog will open based on selection i am displaying the value.. Now the issue is I the timezone value is too length then it will not display look like the below image.. I have to replace it with "..." if its exceed.. If I set max length it will work for this small device.. But the text view size will change based on device width. So I am little confused how to handle this.. can you please help me to solve this issue.

<LinearLayout
    android:layout_width="match_parent"
    android:minHeight=“60dp”
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:layout_marginBottom=“10dp”
    android:visibility="visible">

  <EditText
     android:id="@+id/etZipCode"
     android:padding=“15dp”
     android:layout_marginBottom=“10dp”
     android:singleLine=true
     android:layout_width="match_parent"
     android:layout_weight="1"
     android:layout_height="wrap_content"
     android:maxLength=“8“
     android:inputType="text"
     android:imeOptions="actionNext" />

    <TextView
     android:padding=“15dp”
     android:layout_marginBottom=“10dp”
     android:singleLine=true
     android:layout_width="match_parent"
     android:minHeight="50dp"
     android:layout_height="wrap_content"
     android:layout_weight="1"
     android:drawableRight="@drawable/ic_dropdown_pin"
     android:layout_marginBottom=“10dp“
     android:layout_marginLeft=“5dp”/>
</LinearLayout>
like image 244
Praveen Kumar Avatar asked Dec 03 '22 23:12

Praveen Kumar


2 Answers

Add a drawablePadding attribute along with maxLines and ellipsize.

Try this,

    <EditText
        android:id="@+id/etZipCode"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="10dp"
        android:layout_weight="1"
        android:imeOptions="actionNext"
        android:inputType="text"
        android:maxLength="8"
        android:text="3445"
        android:padding="15dp"
        android:singleLine="true"/>

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="10dp"
        android:layout_marginLeft="5dp"
        android:layout_weight="1"
        android:drawableRight="@drawable/ic_dropdown_pin"
        android:minHeight="50dp"
        android:padding="15dp"
        android:text="Alaska Standard Time"
        android:ellipsize="end"
        android:maxLines="1"
        android:drawablePadding="10dp"
        android:singleLine="true"/>

</LinearLayout>

Screenshot below,

Screenshot

like image 74
K Neeraj Lal Avatar answered Jan 25 '23 21:01

K Neeraj Lal


The suggested solutions with

android:ellipsize="end"
android:maxLines="1"

are correct, but lacks of an important detail. You are applying to your TextView a compound Drawable on the right.. to make the three dots appear in this scenario, you have to apply a android:drawablePadding="{something}dp" attribute to the TextView as well.

Hope it helps!

like image 44
andrea.rinaldi Avatar answered Jan 25 '23 20:01

andrea.rinaldi