android布局(3)相對布局

2021-06-13 08:04:06 字數 1111 閱讀 1459

相對布局的子控制項會根據它們所設定的參照控制項和引數進行相對布局,參照控制項可以是父控制項,也可是其它子控制項,但是被參照的控制項必須要在參照它的控制項之前定義。

示例:relativelayout.xml->

xmlversion="1.0"

encoding="utf-8"

?>

<

relativelayout

xmlns:android=""

android:layout_width="fill_parent"

android:layout_height="fill_parent"

>

<

analogclock

android:id="@+id/aclock"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_centerinparent="true"

/>

<

digitalclock

android:id="@+id/dclock"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_below="@id/aclock"

android:layout_alignleft="@id/aclock"

android:layout_marginleft="40px"

/>

<

textview

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="current time:"

android:layout_toleftof="@id/dclock"

android:layout_aligntop="@id/aclock"

/>

relativelayout

>

效果:

Android布局(相對布局)

relativelayout相對布局裡常用的位置屬性 2.id型xml屬性 android layout above 該元件位於引用元件的上方 android layout below 該元件位於引用元件的下方 android layout toleftof 該元件位於引用元件的左方 android...

Android線性布局,相對布局

android開發有五種常見布局 linearlayout 線性布局 relativelayout 相對布局 framelayout 幀布局 tablelayout 布局 absolutelayout 絕對布局 主要是以水平或垂直的方式來顯示頁面中的控制項,在水平排列情況下,從左到右 垂直情況下,從...

Android相對布局

2 相對布局 如圖 梅花布局 如下 android layout width match parent android layout height match parent android id id no.0 android layout width wrap content android la...