Android Development For Absolute Beginners

Incoggeek
Javarevisited
Published in
7 min readJun 28, 2023
Photo by Denny Müller on Unsplash

Android Basics: UI

Views and its Terminology

A View is a simple building block of a user interface. It is a small rectangular box that can be TextView, EditText, or even a button. It occupies the area on the screen in a rectangular area and is responsible for drawing and event handling.

  • Layout: The layout of an app is the design or arrangement of what the user sees on the screen
  • User Interface: The user interface of an app is what we see on the screen of the Android device. It consists of one or more rectangular areas called Views, which display information. Some of the Views — the buttons, for example — also respond to touch.

A computer is a machine that follows a program. An Android device is a computer and an app is a program. Variables inside the device hold values like numbers or text. An object is a special variable that can contain fields and methods. For example, a MediaPlayer object has fields such as a sound file, volume level, playback position, and loop indicator, as well as methods like play, pause, and stop.

TextView: The TextView that the user sees on the screen is actually a Java object inside the Android device. So when we talk about the TextView, we are referring to the rectangular area on the screen. It’s used to show text on the screen.

ImageView: The ImageView on the screen is actually a Java object on the Android device. It’s easier to think of it as a rectangular area on the screen when talking about what the user sees. It’s used to show images on the screen.

Button: A Button on the screen is created by a Java object inside the Android device. This Java object is the actual Button. But when discussing what the user sees, it is easier to call the rectangular area on the screen the “Button”.

Every View is contained in a larger View called its parent View, and we imagine that the parent of the largest View of all is the glass rectangle of the screen.

  • Hard coding: Hardcode info into the app by adding instructions, e.g. add 10 + 20 or make TextView 100dp wide.
  • match_parent: Set the View’s layout_width to match_parent for full width, and layout_height to match_parent for full height.
  • wrap_content: Specify wrap_content to shrink-wrap the View. Prevent it from wrapping too tightly with padding.
  • padding: View shrinks to content when width/height is set to wrap_content. To prevent tight wrap, add padding. It’s like you are making the view larger by adding space inside of the view.
  1. padding — keep distance from all the inner boundaries
  2. padding-left — keep distance from the left inner boundary
  3. padding-right — keep distance from the right inner boundary
  4. padding-top — keep distance from the top inner boundary
  5. padding-bottom — keep distance from the bottom inner boundary
  • margin: Margin enforces spacing between/around views but not adding space inside the view. Android has 5 margin types.
  1. margin — keep distance on all the four sides
  2. margin-left — keep distance from the left side of the view
  3. marginRight — keep distance from the right side of the view
  4. margin-top — keep distance from the top of the view
  5. margin-bottom — keep distance from the bottom of the view

Android offers five types of margin and padding: Left, Right, Top, Bottom, and Start/End. Each margin and padding type can be used to specify the spacing between views.

ViewGroup

A ViewGroup is a big View that can contain smaller Views inside of it. The smaller Views are called the children of the ViewGroup and might be TextViews or ImageViews. The ViewGroup is called the parent of its children. The illustration shows one of the most common ViewGroups, a vertical LinearLayout.

The ViewGroup itself might be transparent, serving only to contain and position its children. Its children, however, will almost always be visible.

Each child is nested (completely contained) within its parent. A child might have children of its own. For example, the illustration shows a vertical linear layout containing three children. The first is a Relative Layout with two children.

View hierarchy

There is always one View, called the root view, that contains all the other Views (if any). The other Views are children, grandchildren, great-grandchildren, etc., of the root View. The Views, therefore, constitute a family tree, called the View hierarchy.

Views naming convention should be camelCase.

LinearLayout

All children of a Linear Layout are stacked one after the other, so a vertical list will only have one child per row, no matter how wide they are, and a horizontal list will only be one row high (the height of the tallest child, plus padding). A linear layout respects the margins between children and the gravity (right, center, or left alignment) of each child.

RelativeLayout

A RelativeLayout is a ViewGroup that displays the child view in a relative position. The position of each view can be relative to the sibling, (like on the left or below another view), or relative to the position of the main area of the relative layout, like bottom, left, or center.

This layout is very flexible, Android is used to customize. This layout allows us to position our view or components based on the position of relative or sibling views (with the help of the id). Using this layout you can position a view to be toLeftOf, toRightOf, below, or above its siblings. This layout is simple because you can place views anywhere and can be used for overlapping a view onto other views.

Activity.onCreate

There are many classes of objects, and one class is named Activity. When an app is launched, an object of this class is automatically created, and then one of the object’s methods, named onCreate, is called. The instructions of this method tell the device to create and display a user interface for the app. This interface consists of areas on the screen that display information and touch-sensitive areas such as buttons.

Other methods of this Activity object are called automatically when the user interface of this app is covered by another app, for example when the phone starts ringing. A final method, onDestroy, is called when the app’s user interface is no longer needed and can be destroyed. onCreate is the first of these lifecycle methods of the Activity object.

Black Box

If we know how to invoke a method, supply it with data, and get its output, we can consider it a black box: something we can use without understanding its inner workings.

Gradle

A computer is a machine that follows a set of instructions called a program. An Android device is a type of computer and an app is a program.

An app can be made up of lots of instructions and other things like resources like image files. We create these with a desktop application called Android Studio.

Android Studio then uses a tool called Gradle to package the instructions and resources into a file called an APK or Android package. This APK can be moved to an Android device and run.

MVC(Model View Controller)

Understand Android Studio Folder Structure

The Android project contains different types of app modules, source code files, and resource files. We will explore all the folders and files in the Android app.

  1. Manifests Folder
  2. Java Folder
  3. res (Resources) Folder
  • Drawable Folder
  • Layout Folder
  • Mipmap Folder
  • Values Folder

4. Gradle Scripts

Manifests Folder

The AndroidManifest.xml file in the Manifests folder creates our Android application. This file contains information about our app, like the Android version, metadata, states package for Java file, and other parts of the app. It acts as a go-between for the Android OS and our application.

Following is the manifests folder structure in the Android application.

AndroidManifest.xml

Java folder

The Java folder holds all the Java and Kotlin source code (.java) files that we make during app development, including other Test files. If we create a new project using Kotlin, the MainActivity.java file will be automatically created under the package name “com.incoggeek.myfirstkotlinapp” like this:

MainActivity.kt and MainActivity.java

  • Kotlin
  • Java

Resource (res) folder

The resource folder is the most important folder because it contains all the non-code sources like images, XML layouts, and UI strings for our Android application.

res/drawable folder

It contains the different types of images used for the development of the application. We need to add all the images in a drawable folder for application development.

res/layout folder

The layout folder contains all XML layout files which we used to define the user interface of our application. It contains the activity_main.xml file.

res/mipmap folder

This folder contains launcher.xml files to define icons that are used to show on the home screen. It contains different density types of icons depending upon the size of the device such as hdpi, mdpi, xhdpi.

res/values folder

The values folder contains a number of XML files like strings, dimensions, colors, and style definitions. One of the most important files is the strings.xml file which contains the resources.

Gradle Scripts folder

Gradle is an automated build system that uses a set of files to create a build configuration for all parts of our application. The build.gradle (Project) file contains the build scripts and build.gradle (Module) uses plugins and implementations to create the build configuration which is applied to all the modules of our application.

Tip : Almost every mobile app provides users with information, such as emails, social media feeds, or news articles. The goal is to deliver the appropriate information to people in the right place and at the right time. If any of these conditions are not met, users uninstall the app because it is not useful.

I am happy to be able to share it with you guys. I’ll be adding more topics on Android Development. Urgh.. As of now, I’m planning to write another blog post on Intent and context in Android. Thanks for reading. Hit the clap button and drop your comment

--

--