在spinner中显示的数据过多,需要换行,而Android自身提供的android.R.layout.simple_spinner_dropdown_item样式不支持换行,因此参考android提供的样式修改即可。

自定义布局文件:spinner_dropdown_item.xml

直接拷贝自android.R.layout.simple_spinner_dropdown_item,只需修改android:singleLine,将其改为false,即可支持换行。

<?xml version="1.0" encoding="utf-8"?>
<CheckedTextView xmlns:andro> 
    android:id="@android:id/text1"
    style="?android:attr/spinnerDropDownItemStyle"
    android:singleLine="false"
    android:layout_width="fill_parent"
    android:layout_height="?android:attr/listPreferredItemHeight"
    android:ellipsize="marquee" />

 修改后换行不是很美观,建议自定义布局

 

=========================================

//默认的不支持修改字体样式
simple_spinner_item.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:andro> 
    android:gravity="left"
    android:textColor="#2A99FB"
    android:textSize="18sp"
    android:textStyle="bold"
    android:singleLine="true"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ellipsize="marquee" />

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-10-26
  • 2021-11-12
  • 2021-06-21
  • 2022-12-23
  • 2022-12-23
  • 2021-05-02
相关资源
相似解决方案