Skip to main content

How to Make Marquee Text in Android?

Hello Friends, In this tutorial I will be showing how we can create Marquee text in Android.


Step 1:- Creating New Project

Create a new project in Android Studio from File ⇒ New Project Fill the required information like project name and package name of the project. When it prompts you to select the default activity, select Empty Activity and proceed.


Step 2:- Add the following code to res/layout/activity_main.xml.


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    tools:context=".MainActivity">


    <TextView
        android:id="@+id/mScrollingText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="3dp"
        android:ellipsize="marquee"
        android:marqueeRepeatLimit="marquee_forever"
        android:scrollHorizontally="true"
        android:singleLine="true"
        android:fadingEdge = "horizontal"
        android:text="Create a Marquee (Scrolling Text) in Androidx Using TextView. Androidx Marquee (Scrolling Text) Tutorial with Example"
        android:textColor="@color/colorPrimaryDark"
        android:textSize="20sp" />

</RelativeLayout>

In the above code, we have taken text view and ellipsize property as marquee as shown below :-


android:ellipsize = "marquee"
android:fadingEdge = "horizontal"
android:marqueeRepeatLimit = "marquee_forever"
android:scrollHorizontally = "true"
android:singleLine = "true"

Step 3:- Add the following code to src/MainActivity.java


package in.imranalam.app.marqueetext;

import android.os.Bundle;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {
    TextView mText;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mText = findViewById(R.id.mScrollingText);
        mText.setSelected(true);
    }
}

Let’s try to run your application. I assume you have connected your actual Android Mobile device with your computer. To run the app from android studio, open one of your project’s activity files and click Run.

icon from the toolbar. Select your mobile device as an option and then check your mobile device which will display your default screen −


Admin

Hi, I am Imran Alam, Full Stack Developer. Helping local businesses to enhance their reach to customers through Websites, Web / Mobile Application, and Digital Marketing. We offer a long range of services like Website Designing, Android Application, School Management System, LMS Software, Point of Sale (Pos) , SEO, Social media Marketing, and Technical Support as well.

Share via
Copy link
Powered by Social Snap