I use this code to make text move and it moves correctly from right to left.
Nevertheless, I want to make the text in TextView move from left to right.
Here is my current code:
<TextView
android:id="@+id/mylinenews"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="5"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:singleLine="true"
android:text="textmoving textmoving textmoving textmoving textmoving textmoving textmoving textmoving textmoving textmoving "
android:textColor="#fff"
/>
How can I modify this code so the text moves from left to right?
Navigate to the app > res > layout > activity_main. xml and add the below code to that file. TextView is used here to add the text which we want to display on the screen. Here we have used android:ellipsize=”marquee” to add a marquee to our text and android:singleLine=”true” so that our text will show only in one line.
To left align the text in this Textview through layout file, set the android:textAlignment attribute for the TextView to “viewStart”, as shown in the following activity_main. xml layout file.
Use RelativeLayout instead of LinearLayout . There are also many other layouts you can try. Check here for the other type of available layouts. RelativeLayout lets child views specify their position relative to the parent view or to each other (specified by ID).
Use below xml code in anim folder under res :
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/linear_interpolator"
android:fillAfter="true">
<translate
android:fromXDelta="-3%p"
android:toXDelta="3%p"
android:duration="1200" />
</set>
And, just add this to your textview :
yourTextView.startAnimation(AnimationUtils.loadAnimation(activity, R.anim.move));
If you want to shake the text than In Your Activity Use
Animation shake = AnimationUtils.loadAnimation(YourActivity.this, R.anim.shake);
YOUR_TEXT_VIEW.startAnimation(shake);
Create a folder name anim in res i.e. res..> anim and create two xml in anim folder
1) shake.xml
2) cycle.xml
In Your shake.xml write
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXDelta="0" android:toXDelta="20" android:duration="7000"
android:interpolator="@anim/cycle" />
and in your cycle.xml write
<?xml version="1.0" encoding="utf-8"?>
<cycleInterpolator xmlns:android="schemas.android.com/apk/res/android" android:cycles="10" />
Enjoy Animated Text in android text view :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With