Praveen Kumar Praveen Kumar - 4 years ago 211
Android Question

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>

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download