java - Continuously animate Text from left to right -


i'm trying create animation moves textview left right , loop indefinitely. textview want animate:

<textview     android:id="@+id/txttitle"     android:layout_width="280dp"     android:layout_height="wrap_content"     android:textsize="16sp"     android:textstyle="italic"     android:layout_marginleft="20dp"     android:layout_marginright="20dp"     android:layout_margintop="20dp"     android:ellipsize="end"     android:maxlines="1"     android:layout_centerhorizontal="true"     android:layout_below="@id/cardview" /> 

and how trying animate textview:

animation animation = new translateanimation(0, -280, 0, 0); animation.setduration(9000); animation.setrepeatmode(animation.relative_to_self); animation.setrepeatcount(animation.infinite); textview.setanimation(animation); 

what want achieve text start out in center of screen, move right , once first letter leaves screen should reappear on other side.

what want can achieved simple valueanimator.

what first have put 2 identical versions of textview want animate layout. in example layout looks this:

<?xml version="1.0" encoding="utf-8"?> <framelayout     xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="match_parent"     android:layout_height="match_parent">      <textview         android:id="@+id/first"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:layout_gravity="center"         android:textsize="32sp"         android:text="@string/hello_word"/>      <textview         android:id="@+id/second"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:layout_gravity="center"         android:textsize="32sp"         android:text="@string/hello_word"/>  </framelayout> 

then - mentioned - use valueanimator animate translationx property of both views, offset 1 width of screen (since textviews above use match_parent width width equal width of screen , using offset position of 1 of them). code should this:

final textview first = (textview) findviewbyid(r.id.first); final textview second = (textview) findviewbyid(r.id.second);  final valueanimator animator = valueanimator.offloat(0.0f, 1.0f); animator.setrepeatcount(valueanimator.infinite); animator.setinterpolator(new linearinterpolator()); animator.setduration(9000l); animator.addupdatelistener(new valueanimator.animatorupdatelistener() {     @override     public void onanimationupdate(valueanimator animation) {         final float progress = (float) animation.getanimatedvalue();         final float width = first.getwidth();         final float translationx = width * progress;         first.settranslationx(translationx);         second.settranslationx(translationx - width);     } }); animator.start(); 

and result should this:

looing text demo


Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -