LinearLayout
线性布局:只能横向或者纵向布局
取决于orientation属性
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="200dp">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="1"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="2"/>
</LinearLayout>
RelativeLayout
相对布局:可以处于布局的任意位置,例如中心等
属性:
-
layout_centerInParent => 若为true,即处于布局中央(在子组件内使用!!)
-
layout_centerVertical => 父布局的纵向居中
-
layout_centerHorizontal => 父布局横向居中
-
layout_above => 在某个组件的上方,只是上方,不会左右也对齐
-
layout_below => 在某个组件下方,和上方一样不会左右对齐,这两个的参数内容是id值,参照的组件需要有id
-
layout_toLeftOf => 在某个组件左方
-