Android相对布局实例
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.fingergame.MainActivity"
tools:ignore="MergeRootFrame"
>
<!-- 注释不能写在</>标记内 -->
<!-- android:layout_width="fill_parent"这与父组件左右对齐属性结合的效果一致-->
<TextView
android:id="@+id/title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="5dp"
android:gravity="center_horizontal"
android:textSize="20sp"
android:textColor="#0000FF"
android:text="猜 拳 游 戏"
/>
<ImageView
android:id="@+id/photo1"
android:layout_below="@id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="18dp"
android:layout_marginLeft="60dp"
android:src="@drawable/smileface"
/>
<ImageView
android:id="@+id/photo2"
android:layout_below="@id/title"
android:layout_toRightOf="@id/photo1"
android:layout_marginTop="18dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="80dp"
android:src="@drawable/smileface"
/>
<RadioGroup
android:id="@+id/chose1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="18dp"
android:layout_marginLeft="40dp"
android:layout_below="@id/photo1"
android:orientation="vertical"
>
<RadioButton
android:id="@+id/stone1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/photo1"
android:layout_toRightOf="@+id/chose1"
android:layout_marginTop="20dp"
android:checked="true"
android:text="石头" />
<RadioButton
android:id="@+id/scissors1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/stone1"
android:layout_marginTop="20dp"
android:layout_toRightOf="@+id/chose1"
android:text="剪刀" />
<RadioButton
android:id="@+id/cloth1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/scissors1"
android:layout_marginTop="20dp"
android:layout_toRightOf="@+id/chose1"
android:text="布" />
</RadioGroup>
<!-- android:layout_height="wrap_content"以chose1的头部对齐
比用android:layout_marginTop="20dp"更灵活 -->
<RadioGroup
android:id="@+id/chose2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/chose1"
android:layout_marginLeft="70dp"
android:layout_toRightOf="@+id/photo1"
android:orientation="vertical" >
<RadioButton
android:id="@+id/stone2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/chose1"
android:layout_marginTop="20dp"
android:layout_toRightOf="@+id/stone1"
android:checked="true"
android:text="石头" />
<RadioButton
android:id="@+id/scissors2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/stone2"
android:layout_marginTop="20dp"
android:layout_toRightOf="@+id/scissors1"
android:text="剪刀" />
<RadioButton
android:id="@+id/cloth2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/cloth1"
android:layout_marginTop="20dp"
android:layout_toRightOf="@+id/cloth1"
android:text="布" />
</RadioGroup>
<Button
android:id="@+id/ok1"
android:layout_width="75dp"
android:layout_height="35dp"
android:layout_below="@+id/chose1"
android:layout_marginTop="20dp"
android:layout_alignLeft="@+id/chose1"
android:text="确认"
/>
<Button
android:id="@+id/ok2"
android:layout_width="75dp"
android:layout_height="35dp"
android:layout_below="@+id/chose2"
android:layout_marginTop="20dp"
android:layout_alignLeft="@+id/chose2"
android:text="确认"
/>
<TextView
android:id="@+id/copyright"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="5dp"
android:text="©fingergame 2015 | designer:Amy" />
</RelativeLayout>
运行结果:


浙公网安备 33010602011771号