简体   繁体   中英

android animation textview rotate string left to right

I need the String inside the textview to be animated from left to right so that when the text is removed from the right, it can be entered from the left, as shown below.

initial state

The text above (Compute Sentence Probability) must be animated as follows and removed from the image and entered on the other side,as shown below.

animated state

I used the animation below, but in this animation the whole text comes from the right once to the left, and again it does not enter at the same time as the text leaves the other side, and the text does not enter again until the whole text is out.

animation

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

Remove all animation from TextView and

In your xml file add textview

<TextView
    android:id="@+id/tvUsername"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Computer Sentence Probability..........."
    android:singleLine="true"
    android:ellipsize="marquee"
    android:marqueeRepeatLimit="marquee_forever"
    android:scrollHorizontally="true"
 />

In java file simple add this line

TextView tvUsername = (TextView)findViewById(R.id.tvUsername);  
tvUsername.setSelected(true);

This answer work and if you want support right to left can add below code to TextView in xml

android:textDirection="rtl"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM