Marquee Text In Android Using Android Studio

Introduction

 
In this article, we are going to see how to create a Marquee Text in Android using the Android Studio. It will show you a running view of text(I.e) it is like a news header line which is in motion.
 
Step 1
 
Create a new project in Android Studio.
 
Android
 
Give a name to the project and click "Next".
 
Android
 
Select the "Phone and Tablet" and click "Next".
 
Android
 
Select an empty activity and click "Next".
 
Android
 
At last, give the activity name and click on "Finish".
 
Android
 
Step 2
 
Setup the gradle by just locate the Gradle Scripts>>Build. Gradle 1.
 
Android
 
And, type the following dependency in your app's build.gradle.
 
Android
 
Code copy is here.
  1. maven{  
  2. url "https://jitpack.io"}  
Step 3
 
locate the Gradle Scripts>>Build. Gradle 2.
 
Android
 
And, type the following dependency in your app's build.gradle.
 
Android
 
Code copy is here.
  1. compile 'com.github.chuross:extra-textview:1.1.3'    
Step 4
 
Next, go to app >> res >> layout >> activity_main.xml. Select activity page.
 
Android
 
and just type the code as follows.
 
Android
 
The code copy is here.
  1. <RelativeLayout  
  2.   
  3.     xmlns:android="http://schemas.android.com/apk/res/android"  
  4.     xmlns:app="http://schemas.android.com/apk/res-auto"  
  5.     xmlns:tools="http://schemas.android.com/tools"  
  6.     android:layout_width="match_parent"  
  7.     android:layout_height="match_parent"  
  8.     tools:context=".MainActivity">  
  9.   
  10.     <TextView  
  11.         android:layout_width="wrap_content"  
  12.         android:layout_height="wrap_content"  
  13.         android:text="Text you want"  
  14.         android:maxLines="1"  
  15.         android:ellipsize="marquee"  
  16.         android:marqueeRepeatLimit="marquee_forever"  
  17.         android:scrollHorizontally="true"  
  18.         android:id="@+id/TextView03"  
  19.         app:layout_constraintBottom_toBottomOf="parent"  
  20.         app:layout_constraintLeft_toLeftOf="parent"  
  21.         app:layout_constraintRight_toRightOf="parent"  
  22.         app:layout_constraintTop_toTopOf="parent" />  
  23.   
  24. </RelativeLayout>  
Step 5
 
Next, go to app >> java>>Mainactivity.java. Select Mainactivity page.
 
Android
 
And, just type the code as follows.
 
Android
 
Code copy is here.
  1. public class MainActivity extends AppCompatActivity {  
  2.   
  3.     @Override  
  4.     protected void onCreate(Bundle savedInstanceState) {  
  5.         super.onCreate(savedInstanceState);  
  6.         setContentView(R.layout.activity_main);  
  7.   
  8.         TextView tv = (TextView) findViewById(R.id.textView);  
  9.   
  10.         tv.setSelected(true);  
  11.     }  
  12. }  
Step 6
 
After step 4, Sync all the dependency gradle and Mainactivity.java resource files by clicking the Sync button on the top right corner of the Gradle page.
 
Android
 
Step 7
 
Verify the preview.
->After the code is applied, the preview will appear like this.
 
Android
 
Step 8
 
Next, go to Android Studio and deploy the application. Select an Emulator or your Android mobile with USB debugging enabled. Give it a few seconds to make installations and set permissions.
 
Android
 
Run the application in your desired emulator (Shift + F10).
 
Android
 
Explanation of source code
 
The source code provided in this article is just the dependencies of Marquee activity and the code used in activity_main.xml will make the moving process and to define its attributes.
 

Summary

 
In this article we created the app named Marquee Text, then we have inserted a Gradle and we learned how to use the Marquee and Finally, we have deployed that as an output.
 
*Support and Share, Thank You*


Similar Articles