RelativeLayout相对布局实验

原创  灵思致远  2018-05-16

作者 Leansmall

1. 实验内容简介

相对布局可以设置某一个视图相对于其他视图的位置,这些位置包括上、下、左、右。设置这些位置的属性是android:layout_above、android:layout_below、android:layout_toLeftOf、android:layout_toRightOf。除此之外,还可以通过android:layout_alignBaseline属性设置视图的底端对齐。这5个属性的值必须是存在的资源ID,也就是另一个视图的android:id属性值。

2. UI界面布局

RelativeLayout相对布局实验_第1张图片

对应的大纲如下:

RelativeLayout相对布局实验_第2张图片


3. XML代码编写和调试

   android:layout_width="fill_parent"

   android:layout_height="fill_parent"

   android:gravity="center" >

 

   

       android:id="@+id/button1"

       android:layout_width="wrap_content"

       android:layout_height="wrap_content"

       android:text="Button1"

       android:textSize="16dp" />

 

   

       android:id="@+id/button2"

       android:layout_width="wrap_content"

       android:layout_height="wrap_content"

       android:layout_below="@id/button1"

       android:layout_toRightOf="@id/button1"

       android:text="Button2"

       android:textSize="16dp" />

 

   

       android:id="@+id/button3"

       android:layout_width="wrap_content"

       android:layout_height="wrap_content"

       android:layout_below="@id/button2"

       android:layout_toLeftOf="@id/button2"

       android:text="Button3"

       android:textSize="16dp" />

 

   

       android:id="@+id/button4"

       android:layout_width="wrap_content"

        android:layout_height="wrap_content"

       android:layout_above="@id/button2"

       android:layout_toRightOf="@id/button2"

       android:text="Button4"

       android:textSize="16dp" />

 

   

       android:id="@+id/button5"

        android:layout_width="wrap_content"

       android:layout_height="wrap_content"

       android:layout_below="@id/button2"

       android:layout_toRightOf="@id/button2"

       android:text="Button5"

       android:textSize="16dp" />

 

RelativeLayout相对布局实验_第3张图片

你可能感兴趣的:(Android界面和组件,Android新手入门)