Many of our Android lessons refer to features from Android Studio 2.1. However, many students are working with the newer version 2.3.1. One of the primary differences between these two versions is the introduction of
ConstraintLayouts. As mentioned in the previous lesson, Constraint layouts are relatively new, and not all companies or applications use them yet. Therefore, we think it's important to learn both newer Constraint layouts, and standard Relative layouts to best prepare for what you'll likely see on the job.
We'll focus on using standard Relative layouts for the first part of this week. Then, on Wednesday night we'll discuss using Constraint layouts in greater detail in the Further Exploration: Working with Constraint Layouts lesson.
But there's just one tiny hiccup: In newer version of Android Studio (2.2+), Constraint Layouts are automatically created for new activities by default. So, in order to practice Relative layouts we'll need to turn these Constraint layouts back into their Relative cousins. But don't worry, it's not too hard. This lesson will address how to turn the default
ConstraintLayout back into a
Also, note that while following along with lessons to create the MyRestaurants app, it's recommended that you turn your default constraint layouts back into relative layouts, in order to follow the lessons exactly.
We can replace an activity's auto-generated
ConstraintLayout with a standard
RelativeLayout by doing the following, as depicted in the GIF below:
Delete the constraint layout file created automatically when you made a new activity.
Create a new layout file by right-clicking the res/layout directory, and selecting New > Layout Resource files.
Give the new layout file the same name as the constraint layout file you've just deleted. This ensures it will be correctly associated with the corresponding activity.
Erase the default contents of the Root Element field, and replace with RelativeLayout.
Click Ok. You should now have a new
RelativeLayout to work with!
Not too bad, right? But don't worry about memorizing this right now. We'll review this process in the next lesson when we create our first layouts together.