TextView Marquee not working [duplicate]

2018-12-31 19:13发布

This question already has an answer here:

I have tried to use marquee and its not working here is my code, please let me know where im going wrong

<TextView
   android:text="lunch 20.00 | Dinner 60.00 | Travel 60.00 | Doctor 5000.00 | lunch 20.00 | Dinner 60.00 | Travel 60.00 | Doctor 5000.00"
   android:id="@+id/TextView02"
   android:layout_width="200dip"
   android:layout_height="wrap_content"
   android:marqueeRepeatLimit="marquee_forever"
   android:ellipsize="marquee"
   android:singleLine="true"
   android:focusable="true"
   android:inputType="text"
   android:maxLines="1">
</TextView>

i am using android SDK 2.0.1

21条回答
十年一品温如言
2楼-- · 2018-12-31 19:31

Use the following line in your code:

TextView.setSelected(true);
查看更多
旧时光的记忆
3楼-- · 2018-12-31 19:31

Just put these parameters in your TextView. It works :)

    android:singleLine="true" 
    android:ellipsize="marquee"
    android:marqueeRepeatLimit ="marquee_forever"
    android:scrollHorizontally="true"
    android:focusable="true"
    android:focusableInTouchMode="true" 

`

查看更多
余生请多指教
4楼-- · 2018-12-31 19:35

I faced the same problem and this discussion helped me I just replace this line

android:maxLines="1"

with this line in xml

android:singleLine="true"

and it works the line txtView.setSelected(true); was also in my activity.

查看更多
流年柔荑漫光年
5楼-- · 2018-12-31 19:40

You must add the these attributes which is compulsary to marquee

 android:ellipsize="marquee"     
 android:focusable="true"    
 android:focusableInTouchMode="true"     
 android:singleLine="true"     
 android:marqueeRepeatLimit="marquee_forever"     
 android:scrollHorizontally="true"
查看更多
零度萤火
6楼-- · 2018-12-31 19:40

enter image description here

 import android.app.Activity;
 import android.os.Bundle;
 import android.text.TextUtils.TruncateAt;
 import android.widget.TextView;

 public class MainActivity extends Activity {
 private TextView textview;

 @Override
 protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    textview = (TextView) this.findViewById(R.id.textview);
    textview.setSelected(true);

    textview.setEllipsize(TruncateAt.MARQUEE);
    textview.setSingleLine(true);
 }

 }

for more reference click here http://androiddhina.blogspot.in/2015/10/marquee-effect-in-android-textview.html

查看更多
皆成旧梦
7楼-- · 2018-12-31 19:40

Most of the answers are identical,
but also notice that in some cases marquee will not work without specifying of width in dips for the container.
For instance if you use weight in parent container

android:layout_width="0dp"
android:layout_weight="0.5"

marquee may not work.

查看更多
登录 后发表回答