最常用属性
代码
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" //定义一个相对布局 里面的子类默认都是重合在一起的 因为是相对的
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:padding="10dp">
<View //定义一个控件
android:id="@+id/view_1" //设置id
android:layout_width="150dp"
android:layout_height="150dp"
android:background="#99cc00"
/>
<View
android:id="@+id/view_2"
android:layout_width="150dp"
android:layout_height="150dp"
android:background="#ffcccc"
android:layout_marginLeft="10dp"
android:layout_toRightOf="@id/view_1"/> //相对布局的属性,设置当前控件在view_1的右边
<LinearLayout //定义一个线性布局 是相对布局的子类
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_below="@id/view_1" //设置线性布局在view_1的下面
android:background="#3399ff"
android:layout_marginTop="20dp"
android:orientation="vertical">
<View
android:layout_width="50dp"
android:layout_height="50dp"
android:background="#ff9966" />
<RelativeLayout //定义一个相对布局
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#66ff33"
android:layout_marginTop="20dp"
android:padding="20dp">
<View
android:id="@+id/view_3"
android:layout_width="100dp"
android:layout_height="70dp"
android:background="#ff0000" />
<View
android:layout_width="100dp"
android:layout_height="70dp"
android:background="#cc9900"
android:layout_toRightOf="@id/view_3" //设置view在view_3的右边 因为是相对布局的子类
android:layout_marginLeft="15dp"/>
</RelativeLayout>
</LinearLayout>
</RelativeLayout>