Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How make text moving from left to right in Android?

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?

like image 371
Hamdan Hejazi Avatar asked Jan 31 '14 07:01

Hamdan Hejazi


People also ask

How do I make text move on android?

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.

How do I change the text on the left side of my android?

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.

How do I change the position of text in android Studio?

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).


2 Answers

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));
like image 143
The Holy Coder Avatar answered Sep 24 '22 16:09

The Holy Coder


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 :)

like image 45
Subhalaxmi Avatar answered Sep 24 '22 16:09

Subhalaxmi