原创  灵思致远  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代码编写和调试

<?xml version="1.0"encoding="utf-8"?>

   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张图片

更多相关文章

  1. 《Android面试宝典》学习笔记(第二章:布局)
  2. Android中android:visibility的3中属性的剖析
  3. android布局相关属性
  4. Android中drawable各个属性讲解
  5. 【学习笔记】Android常用布局
  6. Android 面试总结之布局常见问题
  7. Android部分控件的特殊属性

随机推荐

  1. Android(安卓)Building System 总结 收藏
  2. Android开发----自动化测试
  3. Google Android操作系统内核编译图文教程
  4. Android中更新UI的四种常用方式
  5. Android开机启动shell脚本(Android(安卓)8
  6. android 图片解码显示流程
  7. Android的Camera架构介绍
  8. 浅谈android的selector,背景选择器
  9. Android(安卓)service后台执行定时任务
  10. Android(安卓)开发之旅:view的几种布局方