Android Spinner包含很长的文本

时间:2018-06-12 11:34:41

标签: java android scroll dropdown

我有一个Spinner(下拉列表),其中包含50行,并且每行包含大约160个以上的字符,问题是前缀直到20个字符对所有人都相同,我的问题是我怎么能做到这一点旋转器可垂直滚动(默认)和水平滚动。

这样我就可以看到整行的价值。

1 个答案:

答案 0 :(得分:1)

使用TextView Horizo​​ntally Scrollabal创建自定义布局,如下所示

custom_spinner.xml

 <TextView
        android:id="@+id/textView1"
        android:text="Scrollable Text" 
        android:singleLine="true"
        android:ellipsize="marquee"
        android:marqueeRepeatLimit ="marquee_forever"
        android:focusable="true"
        android:focusableInTouchMode="true" 
        android:scrollHorizontally="true"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"/>

然后将自定义布局设置为Adapter类(可以是自定义或任何其他类似ArrayAdapter)

ArrayAdapter your_Adapter = new ArrayAdapter(this, R.layout.custom_spinner,your_array);
your_spinner.setAdapter(your_Adapter );