RelativeLayout 相對布局

2021-09-06 07:50:37 字數 2234 閱讀 3332

相對布局的子控制項會根據它們所設定的參照控制項和引數進行相對布局。

參照控制項:aclock控制項與容器之間

android:layout_alignparentleft="true" 位於父容器左上角 android:layout_alignparentbottom, android:layout_alignparenttop, android:layout_alignparentright  只能在父控制項為relativelayout時才起作用,而對於像linearlayout這樣的布局不起作用

android:layout_centerinparent="true" 位於布局容器的**位置;

layout_centerhorizontal位於布局容器水平居中位置;

layout_centervertical位於布局容器垂直居中位置

被參照控制項:控制項與控制項之間位置

android:layout_below="@id/aclock" 位於aclock元件下方  

android:layout_toleftof="@id/dclock"位於dclock元件左則

控制項與控制項之間對齊方式

android:layout_alignleft="@id/aclock"與aclock元件左邊界對齊;

android:layout_aligntop="@id/aclock"與aclock元件上邊界對齊

效果:

**:

1

<

relativelayout

xmlns:android

=""2xmlns:tools

=""3android:layout_width

="match_parent"

4android:layout_height

="match_parent"

5tools:context

=".androidrelativelayoutactivity"

>67

<

analogclock

8android:id

="@+id/aclock"

9android:layout_width

="wrap_content"

10android:layout_height

="wrap_content"

11android:layout_centerinparent

="true"

>

12analogclock

>

1314

2021

<

digitalclock

22android:id

="@+id/dclock"

23android:layout_width

="wrap_content"

24android:layout_height

="wrap_content"

25android:layout_alignleft

="@id/aclock"

26android:layout_below

="@id/aclock"

27android:layout_marginleft

="40px"

>

28digitalclock

>

2930

<

textview

31android:layout_width

="wrap_content"

32android:layout_height

="wrap_content"

33android:layout_aligntop

="@id/aclock"

34android:layout_toleftof

="@id/dclock"

35android:text

="當前時間"

>

36textview

>

3738

relativelayout

>

RelativeLayout相對布局

relativelayout相對布局是個人覺得在android布局中比較常用且好用的乙個,當然如果想讓布局更漂亮是需要多種布局混合搭建的,這裡就需要更深入的學習了,在這只介紹下有關相對布局的東西。相對於兄弟元素 android layout below id aaa 在指定view的下方 andro...

RelativeLayout 重要屬性

第一類 屬性值為true或false android layout centerhrizontal 水平居中 android layout centervertical 垂直居中 android layout centerinparent 相對于父元素完全居中 android layout alig...

relativelayout布局相關

在相對布局 relativelayout 中,子控制項的位置是相對兄弟控制項或父容器而決定的。出於效能考慮,在設計相對布局時,要按照控制項之間的依賴關係排列。如view a的位置相當於view b來決定,則需要保證布局檔案中view b在view a的前面。在進行相對布局時,用到的布局屬性有很多,首...