【问题标题】:Spinner text not wrapping (not in the spinner itself but the view)微调器文本不换行(不在微调器本身中,而是在视图中)
【发布时间】:2017-10-07 08:29:03
【问题描述】:

对于一个项目,我需要创建一个具有多选功能的微调器。微调器内的文本确实可以完美换行,但是当我退出微调器时,文本 (Spinner Text) 不会自动换行,如下所示:Spinner view

只是为了确保:微调器选择效果很好,但当我想在微调器中显示所选项目时却不行

我该如何解决这个问题?

微调器适配器:

simple_adapter = new ArrayAdapter<>(context, R.layout.my_spinner);
    simple_adapter.setDropDownViewResource(android.R.layout.simple_list_item_multiple_choice);

微调器:

<nl.project.name.View.MultiSelectionSpinner
        android:theme="@style/myTheme"
        android:id="@+id/spinner"
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:spinnerMode="dropdown"
        android:dropDownSelector="@color/backGround"
        android:background="@color/colorGrey"
        android:layout_alignParentStart="true"
        android:layout_below="@+id/textView11" />

微调器布局:

<?xml version="1.0" encoding="utf-8"?> <TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:singleLine="false"/>

【问题讨论】:

  • 发布带有问题的代码
  • 你想看什么代码?
  • 你的 Spinner view 没有换行
  • 你需要创建一个根元素为TextView的布局并使用`android:singleLine="false"`
  • 所以像 android.R.layout.simple_spinner_item 但随后使用 singleline ="false"

标签: java android textview android-spinner


【解决方案1】:

您需要创建一个根元素为TextView 的布局并使用android:singleLine="false"

layout_spinner_item.xml

<?xml version="1.0" encoding="utf-8"?>
<TextView 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:singleLine="false"
    android:text="" />

并像这样设置到适配器中

simple_adapter = new ArrayAdapter<>(context, R.layout.layout_spinner_item);

【讨论】:

  • 好的,您是否在 Adapter 构造函数中传递了您的自定义布局?
  • android.R.layout.my_spinner 中删除android 应该是R.layout.my_spinner
  • 遗憾地没有修复它
猜你喜欢
  • 2011-04-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-03-14
  • 2013-09-12
相关资源
最近更新 更多