使用maxLines的选框

时间:2017-02-19 18:34:19

标签: android textview ellipsis

如何使用MaxLines代替SingleLine?

这是我的TextView:

<TextView
    android:text="bla bla bla bla bla bla"
    android:id="@+id/MarqueeText" 
    android:layout_width="30dp"
    android:layout_height="wrap_content" 
    android:singleLine="true"
    android:ellipsize="marquee" 
    android:marqueeRepeatLimit="marquee_forever"
    android:scrollHorizontally="true" 
    android:focusable="true" 
    android:focusableInTouchMode="true" 
    android:freezesText="true">

在我的code.java之后我setSelected我的TextView

TextView txtView=(TextView) findViewById(R.id.MarqueeText);
txtView.setSelected(true);

问题是android:singleLine已被弃用,因此我必须使用android:maxLines,但选框无法使用它。

2 个答案:

答案 0 :(得分:2)

在XML

<TextView
    android:text="11111111111111111111111111111111111111111111111111111111111111"
    android:id="@+id/text_marquee"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:maxLines="1"
    android:ellipsize="marquee"
    android:marqueeRepeatLimit="marquee_forever"
    />

在Java中

((TextView)findViewById(R.id.text_marquee)).setHorizontallyScrolling(true);
((TextView)findViewById(R.id.text_marquee)).setSelected(true);

答案 1 :(得分:1)

你可以试试这个:

android:maxLength = "10"

OR

设置android:maxLines="1"后,您还必须设置inputType。所以,设置你的android:inputType="text",这应该可以解决问题。