【问题标题】:Android's spinner automatic scrolling when text is too long文本太长时Android的微调器自动滚动
【发布时间】:2014-05-20 09:41:13
【问题描述】:

在我的布局中有一个固定宽度的微调器(下拉列表),有些条目比微调器长,所以我希望它们在选择时自动水平滚动。

我知道你可以像这样对 textview 应用自动水平滚动:

<TextView
        android:id="@+id/textView1"
        android:layout_width="50dp"
        android:layout_height="25dp"
        android:ellipsize="marquee"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:marqueeRepeatLimit="marquee_forever"
        android:scrollHorizontally="true"
        android:singleLine="true"
        android:text="Single-line text view that scrolls automatically if the text is too long to fit in the widget" />

我尝试将相同的设置应用于我的微调器,如下所示:

<Spinner
            android:id="@+id/spinner1"
            android:layout_width="90dp"
            android:layout_height="55"
            android:ellipsize="marquee"
            android:entries="@array/country_arrays"
            android:focusable="true"
            android:focusableInTouchMode="true"
            android:marqueeRepeatLimit="marquee_forever"
            android:scrollHorizontally="true"
            android:singleLine="true" />

但它不会滚动。有什么想法吗?

【问题讨论】:

    标签: android scroll spinner horizontal-scrolling


    【解决方案1】:

    Spinner 扩展了由 Adapter 类支持的 AdapterView

    就像您可以自定义 ListView 中的每一行一样,您应该能够通过覆盖 Adapter.getView() 之类的方法为 Spinner 做同样的事情。

    在那里,您可以返回一个带有 ellipsize 属性的简单 TextView。

    希望对你有很大帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-12
      • 1970-01-01
      • 2011-09-28
      相关资源
      最近更新 更多