更新时间:2023-12-04 21:54:04
正如我所提到的:Spinner不换行文字 - 这是一个Android的bug
我觉得这是一个错误的机器人。你可以试试这个。删除从文本的空间,然后显示它会正常工作。如果TextView中的长度为<该字符串,它忽略了空格后的所有字符。对于一个解决方法,你可以试试这个:
I think there is a bug on android. You could try this. Remove the spaces from the text and then display it would work fine. If the length of the textview is < that of the string, it ignores all the characters after the space. For a work-around you could try this :
将文件添加到与样品code名为multiline_spinner_dropdown_item.xml RES /布局文件夹:
add a file to res/layout folder named multiline_spinner_dropdown_item.xml with the sample code:
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/sample_text"
style="?android:attr/spinnerDropDownItemStyle"
android:singleLine="false"
android:layout_width="match_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:ellipsize="marquee" />
和从这种布局,当你创建的微调创建它。
and when you are creating the spinner create it from this layout.
是这样的:
ArrayAdapter.createFromResource(this, items, R.layout.multiline_spinner_dropdown_item);
基本上,复制android.R.layout.simple_spinner_dropdown_item布局到项目,并通过设置单行属性设置为false在CheckedTextView修改布局。
Basically, copy the android.R.layout.simple_spinner_dropdown_item layout into the project and modify the layout by setting singleLine attribute to false in CheckedTextView.