How to animate text (very long text) scrolls horizontally automatically

I'm not interested in Marquee, because in Marquee you cannot control the speed of selection. I tried to animate the text view, but in the Parent View clicks the text at the end, despite the fact that all the parent layouts and view groups spanning textviews are set with two flags clipchildren = false, clipToPadding = false.

Am I missing something or is it better to work there?

xml looks like

<TextView android:id="@+id/textview1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_alignParentLeft="true" android:layout_marginBottom="66dp" android:maxLines="1" android:singleLine="true" android:textColor="#585858" android:textSize="32sp" > </TextView> 

and the code snippet look like

 TextView textView2 = (TextView)findViewById( R.id.textview1 ); textView2.startAnimation((Animation)AnimationUtils.loadAnimation(this, R.anim.translate)); 
+4
source share
10 answers

I think you can use animation translation. Something like that

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

And add the following to your text image

 textview.startAnimation((Animation)AnimationUtils.loadAnimation(Context,R.anim.scroll_animation)); 

Hope this helps you.

+5
source

Just add this to your text.

 <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:ellipsize="marquee" android:textSize="30dp" android:focusable="true" android:focusableInTouchMode="true" android:marqueeRepeatLimit="marquee_forever" android:scrollHorizontally="true" android:singleLine="true" android:text="Your_Text" /> 
+4
source

Here is my DECISION

To make the long text inside the text view not allowed by the parent view or screen, I did two things.

First, let textview inside scroolview as below code

 <ScrollView android:layout_width="wrap_content" android:layout_height="50dp" android:layout_centerHorizontal="true"> <TextView android:id="@+id/marquee_text" android:layout_width="wrap_content" android:layout_height="50dp" android:maxLines="1" android:textColor="@android:color/black" android:textSize="30sp"/> </ScrollView> 

Then I measure my text size and then refine the textview parameter by doing this.

  marqueeText.setText("my long text"); Paint textPaint = marqueeText.getPaint(); String text = marqueeText.getText().toString();//get text int width = Math.round(textPaint.measureText(text));//measure the text size ViewGroup.LayoutParams params = marqueeText.getLayoutParams(); params.width = width; marqueeText.setLayoutParams(params); //refine DisplayMetrics displaymetrics = new DisplayMetrics(); getActivity().getWindowManager().getDefaultDisplay().getRealMetrics(displaymetrics); int screenWidth = displaymetrics.widthPixels; //this is optional. do not scroll if text is shorter than screen width //remove this won't effect the scroll if (width <= screenWidth) { //All text can fit in screen. return; } //set the animation TranslateAnimation slide = new TranslateAnimation(0, -width, 0, 0); slide.setDuration(20000); slide.setRepeatCount(Animation.INFINITE); slide.setRepeatMode(Animation.RESTART); slide.setInterpolator(new LinearInterpolator()); marqueeText.startAnimation(slide); 

I hope this solution, which took me half a day to research, can help others who may encounter the same problem as me.

+3
source

I am sure that this will definitely solve the problem of a large audience.

Q: Automatically scrolling a single-line text message (using hard_coding or from string.xml) horizontally & infinitely at a reasonable speed, but using selection (try at least once). No clipping

Step 1: In the activity_main.xml file:

 <TextView android:text="either hard coding or from string.xml" android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/textView2" android:background="@color/colorPrimary" android:textSize="18sp" android:marqueeRepeatLimit="marquee_forever" android:textColor="@android:color/background_light" /> 

Step 2: In the main_activity java file, the public MainActivity class extends AppCompatActivity {

 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); TextView textView = (TextView) findViewById(R.id.textView2); textView.setEllipsize(TextUtils.TruncateAt.MARQUEE); textView.setSelected(true); textView.setSingleLine(true); textView.setText("Oxfam says 8 men as rich as half the world. | Govt may set threshold for probe into deposits. | At least 32 dead after Turkish plane hits village.");}} 

// you can delete the last line of the line if it already passed a long input

+2
source

Add this animation file:

 <translate android:duration="7000" android:fromYDelta="0%p" android:interpolator="@android:anim/accelerate_interpolator" android:repeatCount="10" android:repeatMode="restart" android:toYDelta="-100%p" /> 

 /*Put your text view inside scroll*/ <ScrollView android:layout_width="@dimen/dp_size_220" android:layout_height="@dimen/dp_size_16" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toRightOf="@+id/iv_myra_notification" app:layout_constraintRight_toLeftOf="@+id/iv_one_way" app:layout_constraintTop_toTopOf="parent"> <TextView android:id="@+id/marquee_text" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="left" android:text="@{itemData.notification.message}" android:textColor="@android:color/black" android:textSize="12sp" tools:text="bfnfkjnvlen jknjkgnojeng"/> </ScrollView> 
+1
source

This is what worked for me. Put the text in the scroll, and then do TranslateAnimation on the scrollview child, in my case it's LinearLayout. I actually add several views dynamically inside this linear layout.

 <ScrollView android:id="@+id/textScrollView" android:layout_width="wrap_content" android:layout_height="match_parent"> <LinearLayout android:id="@+id/textLayout" android:orientation="vertical" android:layout_width="wrap_content" android:layout_height="wrap_content"> </LinearLayout> </ScrollView> TranslateAnimation slide = new TranslateAnimation(0, 0, height, -textLayout.getHeight()); slide.setDuration(movementSpeed); slide.setRepeatCount(-1); slide.setRepeatMode(Animation.RESTART); slide.setInterpolator(new LinearInterpolator()); textLayout.startAnimation(slide); height --> The point start scrolling up (in my case device height (device bottom)) movementSpeed --> scrolling speed 
0
source

Use this easy way with ellipsize and marquee options using @rajath answer

 <TextView android:text="Single-line text view that scrolls automatically if the text is too long to fit in the widget" android:singleLine="true" android:ellipsize="marquee" android:marqueeRepeatLimit ="marquee_forever" android:focusable="true" android:focusableInTouchMode="true" android:scrollHorizontally="true" android:layout_width="wrap_content" android:layout_height="wrap_content"/> 
0
source

You can try it. This is a solution that uses TranslateAnimation to create automatic text scrolling (horizontal scrolling, from right to left) (tested on Android 8)

Class: AnimationAutoTextScroller.java

 /** * A Class for automatically scrolling text horizontally from Right to Left * using TranslateAnimation so that the scrolling speed can be controlled -Suresh Kodoor */ public class AnimationAutoTextScroller { Animation animator; TextView scrollingTextView; int duration = 50000; // default value public AnimationAutoTextScroller(TextView tv, float screenwidth) { this.scrollingTextView = tv; this.animator = new TranslateAnimation( Animation.ABSOLUTE, screenwidth, Animation.RELATIVE_TO_SELF, -1f, Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF, 0f ); this.animator.setInterpolator(new LinearInterpolator()); this.animator.setDuration(this.duration); this.animator.setFillAfter(true); this.animator.setRepeatMode(Animation.RESTART); this.animator.setRepeatCount(Animation.INFINITE); // setAnimationListener(); } public void setDuration(int duration) { this.duration = duration; } public void setScrollingText(String text) { this.scrollingTextView.setText(text); } public void start() { this.scrollingTextView.setSelected(true); this.scrollingTextView.startAnimation(this.animator); } public void setAnimationListener() { animator.setAnimationListener(new Animation.AnimationListener() { public void onAnimationStart(Animation animation) { } public void onAnimationEnd(Animation animation) { // This callback function can be used to perform any task at the end of the Animation } public void onAnimationRepeat(Animation animation) { } }); } } 

Layout XML: (hold TextView under HorizontalScrollView)

  <HorizontalScrollView android:layout_width="match_parent" android:layout_height="wrap_content" android:scrollbars="none" app:layout_constraintBottom_toTopOf="@+id/hguide3" app:layout_constraintEnd_toStartOf="@+id/vguide2" app:layout_constraintHorizontal_bias="1.0" app:layout_constraintStart_toEndOf="@+id/vguide1" app:layout_constraintTop_toBottomOf="@+id/hguide2"> <TextView android:id="@+id/translateanimatortextviewscroller" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="0dp" android:layout_marginEnd="0dp" android:layout_marginLeft="0dp" android:layout_marginStart="0dp" android:layout_marginTop="0dp" android:text="" android:singleLine="true" android:focusable="true" android:scrollHorizontally="true" android:background="#000000ff" android:textColor="#ff0000" android:textSize="55dp" android:textStyle="bold" android:typeface="sans" /> </HorizontalScrollView> 

activity:

 TextView scrollertextview = findViewById(R.id.translateanimatortextviewscroller); textscroller = new AnimationAutoTextScroller(scrollertextview, screenwidth); textscroller.setScrollingText(scrollertext); textscroller.setDuration(60000); textscroller.start(); 
0
source

try this code, it will help you get out of Shri n HERO

 <?xml version="1.0" encoding="utf-8"?> <translate> <translate xmlns:android="http://schemas.android.com/apk/res/android" android:duration="5000" android:fromXDelta="1500" android:interpolator="@android:anim/linear_interpolator" android:repeatCount="infinite" android:repeatMode="restart" android:toXDelta="-1250" /> </translate> 
-one
source
 <translate> <translate xmlns:android="http://schemas.android.com/apk/res/android" android:duration="5000" android:fromXDelta="1500" android:interpolator="@android:anim/linear_interpolator" android:repeatCount="infinite" android:repeatMode="restart" android:toXDelta="-1250" /> 

-one
source

Source: https://habr.com/ru/post/1502398/


All Articles