开发者

Truncated string in android spinners

开发者 https://www.devze.com 2022-12-23 22:46 出处:网络
On the iPhone, if an option is too long for the area, instead of wrappeing you get a \"...\" at the end of the \"drop down\" and the user will know there is more t开发者_JAVA百科ext than is shown.

On the iPhone, if an option is too long for the area, instead of wrappeing you get a "..." at the end of the "drop down" and the user will know there is more t开发者_JAVA百科ext than is shown.

I want to recreate this with android but am new to it so cant see how.

I want the heights of "rows" in my layout to be uniform hence not able to wrap the text.

Thanks in advance.


Use a custom view for that, and specify by calling:

adapter.setDropDownViewResource(R.id.my_simple_spinner_dropdown_item);

Note that you have to use your own view here: my_simple_spinner_dropdown_item.xml

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@android:id/text1"
    style="?android:attr/spinnerItemStyle"
    android:singleLine="true"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:ellipsize="end" />


In the layout you use for your Spinner rows, for the TextView containing the possibly-too-long text, use android:ellipsize="end".


In the layout you use for your Spinner rows, for the TextView containing the possibly-too-long text, use android:ellipsize="end".

I think you have to use the attribute singleLine

You are infact both right, you need to set the ellipsize and the single line attr.


I think you have to use the attribute singleLine, however, I don't know if it is possible with tableLayout or even advisable... try it on a single texteview to see the effect, and then in your TL...

0

精彩评论

暂无评论...
验证码 换一张
取 消