gpt4 book ai didi

Android 的微调器在文本太长时自动滚动

转载 作者:行者123 更新时间:2023-11-30 02:53:16 25 4
gpt4 key购买 nike

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

我知道您可以像这样将自动水平滚动应用到 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" />

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

最佳答案

Spinner 扩展了由适配器类支持的 AdapterView

就像您可以自定义 ListView 中的每一行一样,您应该能够通过重写 Adapter.getView() 等方法为您的 Spinner 执行相同的操作。

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

希望对您有所帮助。

关于Android 的微调器在文本太长时自动滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23756204/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com