Horizontal scrolling text in Android

前端 未结 5 2012
抹茶落季
抹茶落季 2020-12-05 05:53

I\'ve been looking around for quite some time now, and I can\'t get a straight answer for my question.

It\'s quite simple: How can I get a nice scrolling text just l

相关标签:
5条回答
  • 2020-12-05 06:42

    I've figured it out by myself.

    android:ellipsize="marquee"
    android:scrollHorizontally="true"
    android:focusable="true"
    android:focusableInTouchMode="true"
    
    0 讨论(0)
  • 2020-12-05 06:42

    the decision which works for me:

    textView.setSelected(true); 
    textView.setEllipsize(TruncateAt.MARQUEE);
    textView.setSingleLine(true);
    

    without focusable's parameters

    0 讨论(0)
  • 2020-12-05 06:43
    android:ellipsize="marquee"
    
    0 讨论(0)
  • 2020-12-05 06:50

    Make a translate animation in your anim folder like:

    <translate xmlns:android="http://schemas.android.com/apk/res/android"
        android:duration="12000"
        android:fromXDelta="100"
        android:interpolator="@android:anim/linear_interpolator"
        android:repeatCount="infinite"
        android:repeatMode="restart"
        android:toXDelta="-100" />
    

    And then to your textview like:

    yourtextview.startAnimation((Animation)AnimationUtils.loadAnimation(Context,R.anim.youranim_xml));
    

    Hope this might help you.

    Edit:

    Try this:

    <TextView 
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ellipsize="marquee"
    android:fadingEdge="horizontal"
    android:lines="1"
    android:marqueeRepeatLimit="marquee_forever"
    android:padding="4dp"
    android:scrollHorizontally="true"
    android:singleLine="true"
    android:text="Simple application that shows how to use marquee, with a long text" />
    
    0 讨论(0)
  • 2020-12-05 06:53
    1. Use a normal TextView with the following config:

      android:text="your text here"
      android:id="@+id/MarqueeText"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:singleLine="true"
      android:ellipsize="marquee"
      android:scrollHorizontally="true"
      android:focusable="true"
      android:focusableInTouchMode="true" />
      

    The problem with this is that you cannot adjust the speed of the scrolling text.

    1. Enclose a TextView within a ScrollView:

        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
                <TextView
                android:id="@+id/myTextView"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Your Text here" >
            </TextView>
        </ScrollView>

    1. Create custom class and follow this thread
    0 讨论(0)
提交回复
热议问题