How do I apply an ellipsis to the spinner instead of the dropdown views? When I search for terms like spinner custom view
, spinner ellipsis
or spinner long text
I get results for the views in the dropdown.
For example:
- Spinner with long text not working fine
- How to wrap lengthy text in a spinner
- Spinner does not wrap text -- is this an Android bug?
- I have Spinner with some items, some of which have long text
This is not what I'm looking for, I'm looking for the actual spinner text.
An image to illustrate my problem
The content is Recipe for disaster/Freeing king awowogei
but the spinner tries to place it on the next line, which is what I do not want. Instead it should add ellipsis at the end and displaying Recipe for disaster/Freeing king awo...
or something.
The spinner content is loaded from a string array and a custom adapter, this all works fine.
I've tried adding
android:ellipsize="marquee"
android:singleLine="true"
To my custom dropdown view, but that's not working. The spinner does not have properties regarding text wrapping so I cannot find out how to achieve this.
The container for the Spinner has a height of 50dp because I do not want the spinner to be higher than that.
And in case it's relevant the simplified xml code of the views
quest_row.xml
the view that I use in my adapter
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/input_background_color"
android:orientation="horizontal"
android:padding="5dp">
<TextView
android:id="@+id/quest_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:textColor="@color/text"
android:textSize="18sp"/>
</LinearLayout>
quest.xml
the main layout
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<Spinner
android:id="@+id/quest_selector_spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:dropDownWidth="wrap_content"
android:padding="5dp"/>
</LinearLayout>