How to Create Marquee Text in Android?

In this lesson, we will construct Marquee Text in Android Studio. Marquees are scrolling pieces of text that can be shown horizontally or vertically. It is used to display a significant message or headline. It makes the app's UI considerably more appealing. It is important to note that we will be programming in kotlin.

In this article, you will learn how to create your marquee Example of marquee view in Android. So let’s take example of marquee view  in Android of Mobile application.   

Example of Marquee

                                                                                               

Step-by-Step Implementation 

​Step 1: Create a New Project in Android ​studio (File >new  project).


Step 2: Create an main_activity.xml file in your layout folder . path (res>layout) 

Implement the same in​voke the following code inside main_activity.xml file.  

 <?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity3">

<TextView
android:id="@+id/marqueeText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:padding="10dp"
android:scrollHorizontally="true"
android:singleLine="true"
app:layout_constraintEnd_toEndOf="parent"
android:text="Hello guys Welcome to candidroot !! How are you!"
android:textSize="20sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Step 3: Create an MainActivity.kt file in your layout folder 

Implement the same in​voke the following code inside MainActivity.kt file. 

 import android.os.Bundle
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity

class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main4)
val txtMarquee = findViewById<TextView>(R.id.marqueeText);
txtMarquee.setSelected(true);
}
}
Step 4 : Output of the above example.

                                                  

Happy coding!

365Bloggy July 25, 2024
Share this post
Tags
SUBSCRIBE THIS FORM


Archive