Spinner with multi-line elements overlaps the selected element on Froyo

I am trying to create Spinners that look the same in all versions of Android back to Froyo. For this purpose I use HoloEverywhere . Some of the text of a spinner element is more than one line, and I would like it to turn around.

Using the default layout, android.R.layout.simple_spinner_dropdown_item or a replacement replacement for HoloEverywhere , ellipses the text rather than wraps it.

Taking the HoloEverywhere template as the starting point for a custom layout with singleLine set to false , ellipsize set to none , and layout_height set to wrap_content does not help, the text is still disabled.

I can get the text for proper packaging in the drop-down list by wrapping the TextView in LinearLayout , but on Froyo devices this will ruin the display of the selected item: Every time you can't get a uniform look back to froyo jake wharton sheds a single tear.

This method works great on new devices. Drop-down item layouts are great for all devices. But Froyo makes this weird text overlap when I use a custom drop-down layout. Each selection simply stacks on top of the last.

This question: Spinner does not wrap text - is this an Android bug? about wrapping text in Spinners suggests that the only way to do this is to recreate the style from scratch without inheritance, but it sounds crazy and prone to problems.

my_simple_list_item_1.xml:

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="300dp" android:layout_height="wrap_content" > <TextView android:id="@+id/android:text1" android:layout_width="wrap_content" android:layout_height="50dp" android:ellipsize="marquee" android:layout_gravity="center_vertical" android:singleLine="false"/> </LinearLayout> 

Java:

  import org.holoeverywhere.widget.Spinner; spinner1.setAdapter(ArrayAdapter.createFromResource(this, R.array.array_of_strings, R.layout.my_simple_list_item_1)); 
+8
android android-layout styles android-spinner android-holo-everywhere
source share
2 answers

I have found a solution. The text was a wrap because the spinners' initial display could only process text images, and I found another solution recommending using a linear layout. This led to the popup window being correct. As it turned out, adapters have a resource called setDropDownViewResource (), which allows you to set a different view for the drop-down list than what is displayed in the counter selection.

  import org.holoeverywhere.widget.Spinner; ArrayAdapter adapter1 = ArrayAdapter.createFromResource(this,R.array.array_of_strings,R.layout.simple_list_item_1); adapter1.setDropDownViewResource(R.layout.my_simple_list_item_1); spQ1.setAdapter(adapter1); 

in this example simple_list_item is the default view provided by android and mY_simple_list_item

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="300dp" android:layout_height="wrap_content" > <TextView android:id="@+id/android:text1" android:layout_width="wrap_content" android:layout_height="50dp" android:ellipsize="marquee" android:layout_gravity="center_vertical" android:singleLine="false"/> </LinearLayout> 

Now the text is wrapped inside the spinner’s drop-down list AND in the selected spinner.

+8
source share

Looks like you're moving up. I assume that your client will never be able to get 100% reliable and consistent results with wrapped text.

See: Spinner doesn't wrap text - is this an Android bug?

0
source share

All Articles