Implementing the layouts

Now that we know the activities that are needed in this application and have a rough idea of how we want our user interface to look when viewed by the user, we can get into the actual implementation of the user interface.

Create a new Android project in Android Studio and give it the name Tetris no activity. Once the IDE window opens, you will notice that the project structure is similar to the one in Chapter 1, The Fundamentals.

The first thing we need to do is add MainActivity to our project. We want MainActivity to be an empty activity. We can add MainActivity to our project by right-clicking on our source package and selecting New | Activity | Empty Activity:

Name the activity MainActivity, and ensure the Generate Layout File, Launcher Activity, and Backwards Compatibility (AppCompat) checkboxes are ticked.

Upon the addition of the activity to your project, navigate to its layout resource file. It should look similar to the following code:

<?xml version="1.0" encoding="utf-8"?><android.support.constraint.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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.mydomain.tetris.MainActivity">
</android.support.constraint.ConstraintLayout>

Line one of the resource file specifies the XML version utilized in the file as well as the character encoding used. utf-8 is used for character encoding in this file. UTF stands for Unicode Transformation Format. It is an encoding format that can be as compact as American Standard Code for Information Interchange (ASCII)—the most common character format for text files—and can contain any Unicode character. The next eight lines define a ConstraintLayout to be rendered in the UI of MainActivity.

Let's consider the ConstraintLayout in a bit more detail before moving forward.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.9.197