各视图组件按照相互之间的相对位置确定,表示将标签中的元素放置到指定元素的下面是:Android:layout_below=“@id/text”;将该元素放置在text元素下Android:layout_ablove=“@id/text”; 将该元素放置在text元素上Android:layout_toLeftOf=“@id/text”; 将该元素放置在text元素左面Android:layout_alignTop=“@id/text”; 将该元素与text元素上部对齐string.xml文件信息:
- <pre class="html" name="code"><string name="b00">根</string>
-
- <string name="b11">茎</string>
-
- <string name="b22">花</string>
-
- <string name="b33">皮</string>
-
- <string name="b44">叶</string>
Main.xml文件信息:
- <?xml version="1.0"encoding="utf-8"?>
-
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
-
- android:layout_width="match_parent"
-
- android:layout_height="match_parent">
-
-
-
- <Button
-
- android:id="@+id/no.0"
-
- android:layout_width="wrap_content"
-
- android:layout_height="wrap_content"
-
- android:layout_centerInParent="true"
-
- android:text="@string/b00"/>
-
-
-
- <Button
-
- android:id="@+id/no.1"
-
- android:layout_width="wrap_content"
-
- android:layout_height="wrap_content"
-
- android:layout_above="@id/no.0"
-
- android:layout_toLeftOf="@id/no.0"
-
- android:text="@string/b11"/>
-
-
-
- <Button
-
- android:id="@+id/no.2"
-
- android:layout_width="wrap_content"
-
- android:layout_height="wrap_content"
-
- android:layout_above="@id/no.0"
-
- android:layout_toRightOf="@id/no.0"
-
- android:text="@string/b22"/>
-
-
-
- <Button
-
- android:id="@+id/no.3"
-
- android:layout_width="wrap_content"
-
- android:layout_height="wrap_content"
-
- android:layout_below="@id/no.0"
-
- android:layout_toLeftOf="@id/no.0"
-
- android:text="@string/b33"/>
-
-
-
- <Button
-
- android:id="@+id/no.4"
-
- android:layout_width="wrap_content"
-
- android:layout_height="wrap_content"
-
- android:layout_below="@id/no.0"
-
- android:layout_toRightOf="@id/no.0"
-
- android:text="@string/b44"/>
-
-
-
- </RelativeLayout>
显示效果图:整体思路:首先在string.xml中定义文本的值,然后在main.xml中,定义整体布局,首先使用<RelativeLayout>标签定义中间位置,然后以它的位置为中心,定义其他四个按钮位置