Summary of relative layout skills in Android

preface

First of all, you can think about how to use relativelayout without nesting to generate the following layout. If you can, you don't have to look at the following.

analysis

The layout features that the bottom of button 3 is aligned, button 2 is above button 3, the text box is horizontally filled with the remaining area, the top of button 1 is aligned, and the list box is vertically filled with the remaining area.

Next, we will split it into the following two sub questions:

The problem of filling the remaining area horizontally

There are two components in the horizontal direction. One component is wrap wide_ Content (or fixed width). Another component needs to fill the remaining width. The effect is as follows:

A text box on the left and a button on the right

If a LinearLayout layout is nested, it must be very simple. It is also possible to use relativelayout, as follows:

<Button
 android:id="@+id/btn2"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_above="@id/btn3"
 android:layout_alignParentRight="true"
 android:text="按钮2"
 />
<EditText
 android:id="@+id/et"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_alignBaseline="@id/btn2"
 android:layout_alignParentLeft="true"
 android:layout_toLeftOf="@id/btn2"
 />

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>