Note that there are some explanatory texts on larger screens.

plurals
  1. POSpinner does not wrap text -- is this an Android bug?
    primarykey
    data
    text
    <p>If the text of a <code>Spinner</code> item is too long to fit into a single line, the text is not wrapped but cut off. This is <em>only</em> the case for <strong>API level >= 11</strong>. Here are screenshots of Android <strong>4.2.2</strong> (left) which shows the wrong behavior and Android <strong>2.3.3</strong> (right) where it looks as expected.</p> <p><img src="https://i.stack.imgur.com/Marym.png" width="320" /> <img src="https://i.stack.imgur.com/xsXtn.png" width="320" /> </p> <p><code>android:singleLine="false"</code> simply gets ignored here. So as all other tries like <code>android:lines</code>, <code>android:minLines</code>, etc. The <code>TextView</code> somehow seems to be much wider than the window width. </p> <p>I saw other people having the same problem, but no one could find a solution. So, is this a system bug? I don't think this inconsistency between the OS versions can be intended.</p> <hr> <h3>Please note:</h3> <p>There were some answers suggesting relatively simple solutions.</p> <ul> <li><p>Writing a custom <code>Adapter</code> and overriding <code>getView()</code> as well as <code>getDropDownView()</code>. This is not the solution here, because at this point, there is still the original problem: How does the layout have to look like to handle proper line wrapping?</p></li> <li><p>Wrapping the <code>TextView</code> of the drop down view into a parent <code>ViewGroup</code>. Does not work with <code>android:layout_width="match_parent"</code> because the width of the parent strangely seems to be unlimited.</p></li> <li><p>Giving the drop down view a fixed width. This is not suitable with the different widths the <code>Spinner</code> can have.</p></li> <li><p>And of course, no solution is to manually insert <code>\n</code>s anywhere into the text.</p></li> </ul> <hr> <h3>Reproduce with the following code:</h3> <p><strong>UPDATE:</strong> I also uploaded this as a sample project on <a href="https://github.com/robbers/SpinnerBug" rel="noreferrer">GitHub</a>: <a href="https://github.com/robbers/SpinnerBug/archive/master.zip" rel="noreferrer">Download</a></p> <p>/res/values/arrays.xml:</p> <pre><code>&lt;string-array name="items"&gt; &lt;item&gt;Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt.&lt;/item&gt; &lt;item&gt;At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est.&lt;/item&gt; &lt;/string-array&gt; </code></pre> <p>/res/layout/spinner_item.xml:</p> <pre><code>&lt;TextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/text1" style="?android:attr/spinnerDropDownItemStyle" android:layout_width="match_parent" android:layout_height="wrap_content" android:ellipsize="none" android:minHeight="?android:attr/listPreferredItemHeight" android:singleLine="false" /&gt; </code></pre> <p>Set <code>Adapter</code>:</p> <pre><code>spinner.setAdapter(ArrayAdapter.createFromResource(this, R.array.items, R.layout.spinner_item)); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload