標籤:
<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>
運行結果:
Android相對布局執行個體