2017-01-12 2 views
4

Marquee не работает для моего TextView Пожалуйста, проверьте ниже кодAndroid TextView Marquee не работает

XML код для TextView

      <TextView 
          android:id="@+id/mtextcash" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:layout_centerVertical="true" 
          android:layout_marginLeft="30dp" 
          android:ellipsize="marquee" 
          android:fadingEdge="horizontal" 
          android:gravity="center" 
          android:marqueeRepeatLimit="marquee_forever" 
          android:maxLength="5" 
          android:scrollHorizontally="true" 
          android:scrollbars="horizontal" 
          android:singleLine="true" 
          android:text="Simple application that shows how to use marquee, with a long text" 
          android:textColor="@color/white" 
          android:textColorHint="@color/white" 
          android:textSize="25dp" /> 

В активность OnCreate

TextView inputAvailableCash = (TextView) findViewById(R.id.mtextcash); 
inputAvailableCash.setSelected(true); 

Спасибо в Advance

+0

Проблема с вашим значением android: layout_width, которое является wrap_content. проверьте ответ на готовность. –

+1

Возможный дубликат http://stackoverflow.com/questions/10458844/textview-marquee-doesnt-work?rq=1 или http://stackoverflow.com/questions/24165143/textview-with-marquee-is-not- work? rq = 1 –

ответ

1

добавить этот атрибут в XML-файле

android:focusable="true"  
android:focusableInTouchMode="true" 
0

После попробовать, поставив этот Params вашего TextView - Он работает

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

И вы также должны setSelected (истинное):

my_TextView.setSelected(true); 
1

Для ширины эффекта выделения требуется всегда «match_parent» или статический (например, 200dp ... и т. Д.). И программно сделайте его setSelected true, как вы уже сделали, просто сделайте его шириной как match_parent в xml, он будет работать.

Edited XML:

     <TextView 
         android:id="@+id/mtextcash" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:layout_centerVertical="true" 
         android:layout_marginLeft="30dp" 
         android:ellipsize="marquee" 
         android:fadingEdge="horizontal" 
         android:gravity="center" 
         android:marqueeRepeatLimit="marquee_forever" 
         android:maxLength="5" 
         android:scrollHorizontally="true" 
         android:scrollbars="horizontal" 
         android:singleLine="true" 
         android:text="Simple application that shows how to use marquee, with a long text" 
         android:textColor="@color/white" 
         android:textColorHint="@color/white" 
         android:textSize="25dp" /> 

Если, делая match_parent это повлияет на ваш дизайн, то вы должны управлять для его фиксации его ширины или с каким-либо другим способом.

В соответствии с вашим xml-кодом вы используете android: maxLength = "5" означает, что будет введено только 5 символов, чтобы вы могли исправить его ширину на 50dp или любой другой статический размер.

+0

спасибо, я попробовал, я просто забыл удалить андроид: maxLength = "5" из-за того, что он не работает. –

1

Эй проверить этот код, но шатёр работать, когда ваш размер текст т.е. длина longer.its работающие на моей стороне. :)

<TextView 
     android:id="@+id/mywidget" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:ellipsize="marquee" 
     android:focusable="true" 
     android:focusableInTouchMode="true" 
     android:singleLine="true" 
     android:textColor="#2086CA" 
     android:text="Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum." 
     android:textAppearance="?android:attr/textAppearanceSmall" /> 

Надеется, что это помогает. :)

6

Поскольку текст очень и ваш код будет работать, только если вы напишете текст в одной строке. Либо добавьте

android:singleline="true" 

в xml или изменить свой код Java на.

TextView inputAvailableCash = (TextView) findViewById(R.id.mtextcash); 
     inputAvailableCash.setSelected(true); 
     inputAvailableCash.setSingleLine(true); 

Это, безусловно, сработает для вас.

+0

У меня было 'maxLines =" 1 ", но оказалось, что этого недостаточно. 'singleline =" true "' заставил его работать! 10x. – WindRider

0
<TextView android:id="@+id/mtextcash" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_marginLeft="30dp" 
        android:ellipsize="marquee" 
        android:gravity="center" 
        android:marqueeRepeatLimit="marquee_forever" 
        android:scrollHorizontally="true" 
        android:singleLine="true" 
        android:text="Simple application that shows how to use marquee, with a long text" 
        android:textColor="@color/white" 
        android:textColorHint="@color/white" 
        android:textSize="25dp" /> 
Смежные вопросы