If you’ve read about LinearLayout, you’ve already gotten a sense of how to build a simple row and column layout. What should other layouts look like in Android? Today, small white and you share a layout control RelativeLayout worth getting. RelativeLayout is called a RelativeLayout, and it’s a great way to create a more esoteric layout that instantly enhances the texture and texture of the entire APP. Even ConstraintLayout, the latest favorite, is an updated version of RelativeLayout.

So what gives RelativeLayout that kind of power? In fact, from the relative layout of its name, we can actually feel something. Einstein’s famous theory of relativity says it all. It’s relative power! What kind of power does the relative have in the layout? Let’s take a look at the schematic of the following two layouts:

This is a schematic of two simpler layouts. These two layouts look simple, but they’re really not. At least in terms of layout. Because the relative breaks the two-dimensional plane constraints, so that we can gallop in the third dimension. It’s an extra dimension of force, an invisible dimension reduction strike.

So it’s time to let us know where the RelativeLayout dimension reduction hits come from. Let’s go!

I’ve been in the army, running the show

Relative to, what to what, can be relative to day, relative to ground, relative to time. So what’s relative to what in RelativeLayout? The first one we’ve got is a RelativeLayout itself. So what’s simple relative to RelativeLayout, is the child control that’s contained within this RelativeLayout. Let’s see how the child control actually operates in the military.

The general sat in the hall

First of all, we need a general manager to take charge of the overall situation. So we usually put it in the middle of the layout, as shown below:

In the image above, you can see that setting Android :layout_centerInParent to true in the target child will place our “master” target child in the center of the screen. Of course, our commander-in-chief likes to run to the middle of the top, so we can use Android :layout_centerHorizontal, its function is to tell the army account, this boss is going to the middle of the top, as shown in Figure 4 below. Assuming, of course, that there are no other people to pull the manager, that there are no other constraints. There is even more outrageous, when a very stupid general, to dress inwardly general, quietly occupy the side of the middle seat, you can use Android :layout_centerVertical, it will roll off.

So as shown above, layout_centerInParent, layout_centerHorizontal, layout_centerVertical are the control child relative to a relative parent. Layout_centerHorizontal is in the center, layout_centerVertical is in the center, Layout_centerInParent = layout_centerHorizontal + layout_centerVertical.

All right, we’re done with the manager, time to bring in the generals. What is called…

The general sat around

Now that the general has been seated, the generals can start to sit around them in a circle. Usually the generals will sit around the general in opposite directions, as shown in the following picture:

Android :layout_alignParentTop, Android :layout_alignParentBottom, Android: layout_layparentright, Android :layout_alignParentLeft :layout_alignParentLeft :layout_alignParentLeft :layout_alignParentLeft Of course, we can arrange four generals to sit in the center of each side by layout_centerVertical or layout_centerVertical to show respect.

So we know layout_alignParentTop, layout_alignParentBottom, layout_alignParentLeft, Layout_alignParentRight is to control the child control relative RelativeLayout square layout, head to head, foot to foot.

What else is missing? Oh, and little soldiers! Batman…

The little soldier is under the hall

Yes, the little soldier is under the hall. What’s going on here? ! Take a look at the scene, as shown in Figure 6:

The general was surprised how the little soldier ran to the front of the general, this guy is also too good to flatter, really flatter the horse all not as good as ah! So how did the soldier do it? Look at that. It looks like the soldier didn’t do anything. Look at the soldier and the general did the same thing, really do not want to be a general soldier is not a good soldier ah. But even so, also can’t let the little soldier run to the general in front of the flattery. What’s going on? In fact, there are other military accounts. The high and low positions are set in the military tent. According to the respect of the status, the low position is arranged in the hall, which makes the secret of the small soldiers in the hall. The dominant factor in a RelativeLayout is usually order, with the person who comes next being more respected. Of course, there are other ways to change this state of affairs.

So Naturally RelativeLayout is not a 2 dimensional layout container, it’s 3 dimensional, it’s just hidden, we don’t know about it. So don’t think you’re going to have a RelativeLayout that’s going to sequence you down, that’s not realistic. If we need to stagger, then we need to work harder.

Well, that’s the end of the tour. Wait, the general has ordered a meeting…

Autumn on the battlefield

Well, the general has just ordered that all the generals be called to order as urgently as a decree. The generals have joined the army and taken their places. The general opened the sand table, and all the generals got up and came to the general’s side.

Surrender the

Naturally, the discussion revolves around the manager. Otherwise, is not too do not take the general in view, since ancient times is no joke in the army. Therefore, all the generals can only obediously come to the commander-in-chief’s side and listen to the teachings, as shown in the following figure:

As is shown in the picture above, the general runs to the side of the general. At this time the generals revolve around the commander-in-chief. So what we’re going to do here is we’re going to use another set of relative properties relative to the other child controls. Make the general relative to the general, not just relative to the army. This is where you need to use a winning formula: Android :layout_above, Android :layout_below, Android :layout_toRightOf, Android :layout_toLeftOf. This magic weapon tells the general whose side he should be on and where he should be. Of course, first the general should move to the center by layout_centerInParent, and then control how close the general should move to the center by margin. Margin: negative margin: negative margin: negative margin: negative margin

Of course the generals found that they were hot against the general’s cold ass. Why is that? In the case of layout_toLeftOf, it is meant to place the control to the left of the reference control, which translates to my right next to your left. It’s always like a hot face against a cold ass. But it works. Of course, the wise general found it possible not to attach your cold ass, so there is another set of talisman: layout_alignTop, layout_alignBottom, layout_alignLeft, and layout_alignRight, which means head to head and foot to foot alignment. So there’s no embarrassment of hot face against cold ass.

I forgot. Where’s the soldier? ! Oh, oh, it’s still there!

JuAnJiMei

Of course, there are many stories in the army. So it is hard to avoid the flowers, the eyebrows. But romance novels are too difficult to write, give xiao Bai a break, just layout_alignBaseline.

Even if it is dead, not before the name

Although thousands of people I go. Generals die in battle, strong men return ten years, the duty of soldiers is to defend the country, defend the border and protect the soil. In the end, it is cold and cold on the battlefield. Our most hope is that the country is still peaceful and the people are safe. The same is true for RelativeLayout. RelativeLayout can also be a silent layout guardian. White also likes to use a RelativeLayout to build the bottom popover, which looks like this:

He who lives and dies for the benefit of his country should not avoid it for good or evil. Just a little bit for reference

`

<ListView android:id="@+id/book_list" android:layout_width="match_parent" android:layout_height="match_parent" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:layout_alignParentBottom="true" android:background="@color/colorDarkGray"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:background="@color/colorWhite"> <ImageView android:layout_width="0dp" android:layout_weight="2" android:layout_height="120dp" android:src="@mipmap/ic_book1_round"/> <TextView android:layout_width="0dp" android:layout_weight="6" android:layout_height="match_parent" android:text="@string/book1_name" android:padding="@dimen/small_spacing" android:gravity="center"/> </LinearLayout> <TextView Android :layout_height="wrap_content" Android :text=" Android :paddingTop="@dimen/small_spacing" Android :paddingBottom="@dimen/small_spacing" android:paddingLeft="@dimen/default_spacing" android:paddingRight="@dimen/default_spacing" android:textColor="@color/colorWhite" /> <TextView android:layout_width="match_parent" Android :layout_height="wrap_content" android:text=" Tsinghua University Press "Android :paddingTop="@dimen/small_spacing" Android :paddingBottom="@dimen/small_spacing" android:paddingLeft="@dimen/default_spacing" android:paddingRight="@dimen/default_spacing" android:textColor="@color/colorWhite" /> <TextView android:layout_width="match_parent" Android: layout_height = "wrap_content" android: text = "ISBN: 9787302512608" android:paddingTop="@dimen/small_spacing" android:paddingBottom="@dimen/small_spacing" android:paddingLeft="@dimen/default_spacing" android:paddingRight="@dimen/default_spacing" android:textColor="@color/colorWhite" /> </LinearLayout>Copy the code

`

A man should let his hair down

As a real man, he should be free from trivial matters. This sentence is for myself, and also for everyone. That’s a pretty good quote for the application of RelativeLayout. A real man doesn’t care about petty matters. The same thing with RelativeLayout. Don’t use Relative Layout to Layout subtle patterns between rows and columns. That’s what other Layout containers like LinearLayout do. A man when informality, RelativeLayout mind when broad, suitable for pointing to a country, a party. So try to use a large layout with a RelativeLayout that is too detailed and affects performance. So just a quick mention, it says here that RelativeLayout is going to measure the control space twice, so it’s not a tattletale.