开发者

TextView with gravity=center and ellipsize=marquee?

I have a TextView with possibly very long text. Also the text should be centered when it is short enough to not cause the marquee effect.

This is the layout xml:

<TextView 
    android:id="@+id/TextView01" 
    android:layout_height="wrap_content"
    android:textColor="#000000" 
    android:gravity="center" 
    android:textSize="12dp"
    android:layout_width="fill_parent" 
    android:focusable="false" android:lines="1"
    android:marqueeRepeatLimit="marquee_forever" 
    android:focusableInTouchMode="false" 
    android:ellipsize="marquee" 
    android:scrollHorizontally="true"></TextView>

also, I use findViewById(R.id.TextView01).setSelected(true) to immediately start the marquee.

When the text becomes too long and the marquee effect would kick in it just disappears. Short text is displayed and works.

When I remove the android:gravity="center" the text is visible and marquee works. But short text will no longer be centered in the TextView. What am I doing wrong?

Edit: I'm using Android 2.2.

Edit2: When I replace android:lines="1" with the (deprecated) android:singleLine="true" everything works as expected, but this does not seem to be an idea开发者_开发问答l solution.


Try to change the attribute android:line="1" to android:singleLine="True". It works fine for me.


Change the android:lines="1" attribute to android:inputType="text". Seems like a bug though.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜