This article documents the author's first experience developing an Android application using Kotlin and XML, detailing the creation of a "Hello Android" app that features a bouncing text animation and a toggle button to control it. The author reflects on the challenges of learning Kotlin, understanding the Android project structure, connecting UI elements to code, and implementing a background thread for the animation, providing a beginner's perspective on fundamental Android development concepts.
Alexander S. Ricciardi
February 24, 2025

Learning platform-based application development is not an easy endeavor. In this article, I reflect on my first exposure to Android app development using Kotlin and XML, providing an overview of a simple "Hello Android" application. I describe the application's functionality and testing scenarios, including the pseudocode, Kotlin code, and output screenshots. I also reflect on the obstacles faced during development and the skills I acquired.
App Description
The app is a simple Hello Android Application written in Kotlin. It displays a simple animation where a TextView ("Hello Android!") bounces around within the screen's boundaries. It also provides a toggle button allowing the user to stop and restart the text animation.
Additionally, the program uses a background thread to run a text animation within an infinite loop. This loop updates the TextView's position and, when hitting a screen boundaries, the text bounces and changes color.
This ‘hands-on’ animation approach is implemented for learning purposes, it is generally better and good practice to use Android API’s built‑in animation classes (like those in AnimationUtils). Furthermore, to initialize the application, I used the Empty View Activity Template from Android Studio. Then I modify the files to implement the text animation and my icon.
The source code files for this application can be found on my GitHub page in the following repository Module-1-Critical-Thinking.
The app was developed using the Android Studio IDE (Integrated Development Environment).
Project Map:
CTA1 Hello Android App.docx (this file, App documentation)
MainActivityPseudo.txt (Main Activity pseudocode)
The project used files from the Android Studio’s Empty View Activity template. Additionally, only the template files that were modified to accommodate the functionality of the application are listed below:
MainActivity.kt (Kotlin code, application logic)
Main_activity.xml (XML code, main UI layout)
Value
string.xml (resource file storing strings)
The following files have been overridden or modified to accommodate my icon. If you do not want to use my logo, do not use these files. The template will automatically use the Android icon.
Value
color.xml
theme.xml (this file was not modified or overridden, but it is part of the value folder)
drawable
ic_launcher_background.xml
ic_launcher_foreground.xml
mipmap-anydpi-v26
ic_launcher.xml
ic_launcher_round.xml
mipmap folders (hdpi; mdpi; xhdpi; xxhdpi; xxxhdp – different variation of my icon)
Reflection
This is my first time using Kotlin and Android Studio to create a program. Installing Android Studio was straightforward. Learning about Kotlin from the textbook and doing research about it was rewarding. The following is an overview of Kotlin based on what I have learned from the textbook and my research.
Kotlin is often described as the most succinct language, meaning that is the least error-prone programming language (Horton, 2019). Android SDK (Software Development Kit) is written in Java. Moreover, Kotlin is fully interoperable with Java, meaning that Java libraries and frameworks can be easily integrated into Kotlin code, and Java projects also can be easily migrated to Kotlin.
It is an Object-Oriented Programming language (OOP).
It includes null safety, preventing null pointers.
It allows function extensions, that is adding functionality to existing classes without modifying their source code.
It allows data classes which are classes primarily used to hold data.
It can implement coroutines, making asynchronous programming much easier such as handling network requests.
(Ricciardi, 2025)
Furthermore, it is generally preferred for Android app development over programming languages like C++ and Java. The table below lists some of the advantages Kotlin has over C++ and Java.
Table 1
Kotlin’s advantages over C++ and Java

Note: The table lists the advantages that Kotlin has over C++ and Java when developing Android based Apps. From “Why Kotlin is preferred for Android app development” by Ricciardi (2025).
As described previously, I chose to create a “Simple Hello Android APP” by modifying the Empty View Activity Template from Android Studio and implementing a background thread to run a text animation within an infinite loop. This loop updates the TextView's position and, when the text hits a screen boundary the text bounces and changes color. This was done to practice implementing variables and loops using Kotlin.
Kotlin Variables Handling
Kotlin uses type inference, type check, and smart-cast, meaning that, when type referring, the compiler automatically deduces the data types of variables and expressions, eliminating the need for explicitly declaring variable types (App Dev Insights, 2023). Type checks are performed in two ways by using the ‘is’ operator and its negation ‘!is’. These operations return a Boolean, that is return true if the condition is met. For example, if a variable ‘is’ of the data typed checked the condition will return true if not it will return false. Smart-cast allows the compiler to cast a variable to a specific type within a code block, without the need for explicit type checks and casts; for example, 'print(x.length) // x (a string) is automatically cast to String'.
Furthermore, Kotlin uses two different keywords to declare variables, ‘val’ and ‘var’ (Developers, n.d.). ‘val’ is used to declare static variables, variables that never change, and ‘var’ is used to declare non-static variables, variables whose value can change. Kotlin's syntax is very similar to Java, and transitioning from Java to Kotlin for this assignment was traits forward. The part that was most challenging for me was learning the Android Project Structure, that is how the project files are interconnected using the Android Manifest file and Gradle build configurations
My Android Project File Structure
Learning my project file structure dependencies was essential for me to understand how different parts of the application interact and to implement a functional code. Below is a breakdown of the key components and their description:
Figure 1
Hello App Structure on Android Studio

Note: The figure illustrates the Hello App file structure in Android Studio.
Note that the MainActivity.kt and activity_main.xml are the core files of the application.
The MainActivity.kt file contains the Kotlin source code dictating the logic for the application, in this example the logic for the bouncing text background animation thread and the toggle button.
The activity_main.xml contains the XML code that defines the user interface layout, including the TextView for the "Hello Android!" text and the ToggleButton.
The ic_launcher files have been modified or overridden to accommodate my personal icon.
The color.xml file has been modified to integrate a color background for my icon.
The strings.xml file has been modified to store the ToggleButton text describing its state and the bouncing_text (“Hello Android!”)
Pseudocode and Koltin Code
Implementing the animation of the bouncing text was not very difficult as I had implemented this functionality in other programming languages, more specifically Java and Python. The most difficult part was understanding how to get the elements from the UI so they could be integrated into the application logic (MainActivity.kt). The Android environment uses ‘id’ to accomplish it. For example, to get the size of the screen (‘View’) to set the boundaries of the text animation, I use the ‘id’ of the element ‘View’ from the activity_main.xml layout file after I imported it and set it as the application content view using this following line of code 'setContentView(R.layout.activity_main)' Below is a Kotlin code snippet demonstrating how this process is done:
Code Snippet 1
Using Ids to Connect Logic and UI
// Set content view, the UI from the activity_main.xml layout file
setContentView(R.layout.activity_main)
// Layout's views attribute from activity_main.xml layout file
val container = findViewById<View>(R.id.main) // The root container (ConstraintLayout)
// The TextView that will bounce
val textView = findViewById<TextView>(R.id.bouncingText)
// Button to start/stop the animation
val toggleButton = findViewById<Button>(R.id.toggleButton)
Note: The Kotlin code snippet illustrated how UI (layout) and Logic are connected using ids. This code is part of the onCreate function.
The other challenging part was understanding the functionality of the
'ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main))' method within the onCreate function, to keep it simple, the code functionality avoids overlaps between window insets (UI element of the app behind system elements) with system UI elements (e.g. Status Bar, Navigation Bar). If the app's content overlaps with the system UI elements, it can lead to poor user experience.
Figure 2
Main Activity Pseudocode

Note: The figure illustrates a snapshot of pseudocode implementing the logic of a text view bouncing and changing color within a container (presumably a screen). The animation runs in a background thread. Additionally, the code implements a toggle button to stop and restart the animation. Furthermore, this pseudocode was created with an Android application perspective in mind and is intended to be translated into Kotlin. Please see MainActivityPseudo.txt file, the complete code here: Module-1-Critical-Thinking.
Figure 3
Main Activity Kotlin (MainActivity.kt)

Note: The figure illustrates a snapshot of Kotlin code implementing the logic of a text view bouncing and changing color within a container (a screen). The animation runs in a background thread. Additionally, the code implements the logic of a toggle button to stop and restart the animation. Please see MainActivity.kt file, the complete code here: Module-1-Critical-Thinking.
Code Snippet 4
Main Activity XLM Layout UI (main_activity.xml)
==========================================================================
This file is a resource file written in XML that defines the user interface layout,
including the TextView for the "Hello Android!" text and the ToggleButton.
It is part of the Simple Hello Android App
Author: Alexander Ricciardi
Date: 02/14/2025
Requirement: Kotlin and XML
Program Description:
This is a simple Hello Android Application written in Kotlin.
It displays a simple animation where a TextView ("Hello Android!") bounces around within
the screen's boundaries.
It also provides a toggle button allowing the user to stop and restart the text animation.
==========================================================================
-->
<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=".MainActivity">
<TextView
android:id="@+id/bouncingText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/bouncing_text"
android:textSize="24sp"
app:layout_constraintBottom_toTopOf="@+id/toggleButton"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/toggleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/toggle_button_state1"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginBottom="16dp" />
</androidx.constraintlayout.widget.ConstraintLayout>
Note: The XML snippet illustrates the UI layout of the application. Please also see main_activity.xml file for the code.
To connect the elements from the UI, this file (main_activity.xml), to the application logic, Android uses elements’ ‘ids’; for example the ‘TextView’ element as an ‘id’ associated with ‘bouncingText’ as illustrated by the following code lines:
Figure 4
Connecting Variables

Note: The figures illustrate how variables interconnect within the Andriod ecosystem.
Screenshots
This section demonstrates the output of the applications using GIF format images.
Figure 5
Bouncing Text and Toggle Button

Note: The figure GIF animation depicts the ‘Hello Android!’ text bouncing and changing color, from black to dark green after bouncing off the edge of the screen. It also depicts the user clicking on the toggle button to stop and restart the animation. Note that the button text all changes from ‘Stop Animation’ to ‘Start Animation’ when first clicked and then from ‘Start Animation’ to ‘Stop Animation’ when clicked again.
Figure 4
Icon and Home Buttons

Note: The figure GIF animation depicts a user using the ‘Home’ and the application icon buttons. Note that the animation seems not to be fluid, this is due to the GIF animation looping, not the application animation itself.
Summary
The "Simple Hello Android App" project provided me with a good foundation for understanding Android development using Kotlin and XML. The process of creating the bouncing text animation and the toggle button helped me to become more familiar with Kotlin, how it is used to implement the application logic (MainActivity.kt), and how it interconnects with the XML UI design (using ConstraintLayout, TextView, and Button in activity_main.xml), and the application resources (e.g. strings.xml). Understanding the Android project structure, connecting UI elements to Kotlin code via resource ‘ids’, and managing a background thread for animation, were the most challenging parts of the project. Ultimately, the project provided me with a solid grasp of fundamental Android concepts and its ecosystem.
References:
App Dev Insights. (2023, December 16). Kotlin Type inference, Type check, Smartcast - App Dev Insights. Medium. https://medium.com/@appdevinsights/kotlin-type-inference-type-check-smartcast-49c5f98fac1b
Developers (n.d.). Learn the Kotlin programming language. Android. https://developer.android.com/kotlin/learn
Horton, J. (2019). Android programming with Kotlin for beginners. Packt Publishing. ISBN: 9781789615401
Ricciardi, A. (2025, February 14). Why Kotlin is preferred for Android app development. Level Up Coding │ Medium. https://medium.com/gitconnected/why-kotlin-is-preferred-for-android-app-development-c1d8f10ad95c