

Since the parent view covers the whole screen of mobile hence the view gets placed in the middle of the mobile screen vertically. This places the view vertically in the center of the parent. (See the yellow view in the above figure)

As our parent view covers the whole screen of mobile therefore the view gets placed in the middle of the mobile screen horizontally. This places the view horizontally in the center of the parent. So the complete screen is our parent view. When you want to place your Views in the center relative to the parent, you can use the following 3 attributes:īefore we learn about the different attributes, we want to specify that the parent in our example is also a Relative Layout with height and width set as match_parent, therefore it will cover the whole screen of mobile. To know how a RelativeLayout works, lets see and understand the most common attributes of RelativeLayout. RelativeLayout is the most commonly used layout in GUI designing. Similarly, the position of each view can be specified relative to its sibling elements (such as to the left-of or below another view) or in terms of position relative to the parent. Student B will know where he/she has to sit. Relative Layout is a layout which arranges views/widgets/ viewGroup according to the position of other views/widgets/viewGroups i.e the new views are placed relative to the already existing views.įor example in a class, if a Student A is sitting on a chair and the teacher of the class asks Student B to sit to the right of the Student A.
#CONSTRUCT 3 RELATIVE TOS CREEN ANDROID#
Android SDK Manager & required Packages.
