Marquee using maxLines

萝らか妹 提交于 2019-12-01 20:33:23

问题


How can I have a marquee using MaxLines instead of SingleLine ?

This is my 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">

After in my code.java I setSelected my TextView :

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

The problem is android:singleLine is deprecated so I have to use android:maxLines instead but the marquee don't work with it.


回答1:


You can try using this :

android:maxLength = "10"

OR

After setting android:maxLines="1", you have to set your inputType too. So, set your android:inputType="text" and that should do the trick.




回答2:


In 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"
    />

In Java

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


来源:https://stackoverflow.com/questions/42331184/marquee-using-maxlines

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!