- 浏览: 66193 次
- 性别:
- 来自: Mercury
最新评论
一、相对布局的基本概念
一个控件的位置,取决于它与其他控件的关系,使控件更加灵活,能够创建更加复杂的布局。
二、相对布局与其他部件的区别
相对布局控件的位置是依赖于它周围其他控件的关系,好处比较灵活,缺点不直观,较为复杂
三、相对布局常用属性介绍
例子程序:
main.xml
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:padding="10px" > <TextView android:id="@+id/label" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Type here:" /> <EditText android:id="@+id/entry" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@android:drawable/editbox_background" android:layout_below="@id/label" /> <Button android:id="@+id/ok" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/entry" android:layout_alignParentRight="true" android:layout_marginLeft="10px" android:text="OK" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toLeftOf="@id/ok" android:layout_alignTop="@id/ok" android:text="Cancel" /> </RelativeLayout>
android:layout_above —— 将该控件的底部至于给定ID的控件之上。
如:@id/myButton,当前控件在myButton上面
android:layout_below —— 将该控件的顶部至于给定ID的控件之下
android:layout_toLeftOf —— 将该控件的右边缘和给定ID的控件的左边缘对齐
android:layout_toRightOf —— 将该控件的左边缘和给定ID的控件的右边缘对齐
android:layout_alignBaseline —— 该控件的baseline和给定ID的控件的baseline对齐
android:layout_alignBottom —— 将该控件的底部边缘与给定ID控件的底部边缘
android:layout_alignLeft —— 将该控件的左边缘与给定ID控件的左边缘对齐
如:@id/myButton,当前控件左边缘和myButton的左边缘是对齐的
android:layout_alignRight —— 将该控件的右边缘与给定ID控件的右边缘对齐
android:layout_alignTop —— 将给定控件的顶部边缘与给定ID控件的顶部对齐
android:alignParentBottom —— 如果该值为true,则将该控件的底部和父控件的底部对齐
android:layout_alignParentLeft —— 如果该值为true,则将该控件的左边与父控件的左边对齐
android:layout_alignParentRight —— 如果该值为true,则将该控件的右边与父控件的右边对齐
android:layout_alignParentTop —— 如果该值为true,则将空间的顶部与父控件的顶部对齐
android:layout_centerHorizontal —— 如果值为true,该控件将被至于水平方向的中央
android:layout_centerInParent —— 如果值为true,该控件将被至于父控件水平方向和垂直方向的中央
android:layout_centerVertical —— 如果值为true,该控件将被至于垂直方向的中央
运行结果:
发表评论
文章已被作者锁定,不允许评论。
-
Android40_Dialog
2011-11-14 00:11 2949Dialog是Android常用的对话框控件。AlertDia ... -
Android39_Clock和TimePicker
2011-11-14 00:08 2319一、AnalogClock和DigitalClock ... -
Android38_ImageView和Gallery
2011-11-14 00:07 3566一、ImageView使用方法 ImageVi ... -
Android37_JSON数据解析
2011-11-08 00:14 2307一、JSON介绍 JSON(JavaSc ... -
Android36_Animations使用(四)
2011-11-08 00:14 3382一、LayoutAnimationsContrlller ... -
Android35_Animations使用(三)
2011-11-08 00:13 2614一、AnimationSet的具体使用方法 ... -
Android34_Animations使用(二)
2011-11-08 00:12 1923在代码中使用Animations可以很方便的调试、运行 ... -
Android33_Animations使用(一)
2011-11-08 00:12 2248一、Animations介绍 Anima ... -
Android31_AppWidget使用(二)
2011-11-05 00:09 2465一、PendingIntent介绍 PendingIn ... -
Android30_AppWidget使用(一)
2011-11-05 00:08 2231一、App Widget定义 App ... -
Android32_Notification用法
2011-11-05 00:09 1846Android系统的状态栏(Status Bar)中有一 ... -
Android29_SeekBar和RatingBar
2011-11-02 23:21 2076一、使用SeekBar步骤: SeekB ... -
Android28_ExpandableListActivity
2011-11-02 23:21 1461ExpandableListActivity就是可扩展的 ... -
Android27_AutoCompleteTextView
2011-11-02 23:21 1035一、创建AutoCompleteTextView ... -
Android26_DatePicker
2011-11-02 23:20 1750一、DatePicker和DatePickerDialo ... -
Android25_Spinner使用方法
2011-11-02 23:20 2778一、创建Spinner的步骤 1.在布局 ... -
Android24_Service初步
2011-10-18 22:27 969一、Service概念 ... -
Android23_Socket编程
2011-10-18 22:19 1472一、什么是Socket Socket是基 ... -
Android22_WIFI网络操作
2011-10-18 22:12 1656一、什么是WIFI WIFI就是一种无线 ... -
Android21_广播机制(二)
2011-10-18 22:00 965一、注册BroadcastReceiver的方法 ...
相关推荐
android_tabHost布局之一_继承TabActivity并以activity布局.doc
NULL 博文链接:https://byandby.iteye.com/blog/830048
其中包含LinearLayout、TableLayout、RelativeLayout布局方式,对于初学Android者有较好的借鉴意义。
10、Android09--Android程序界面 11、Android11--基本布局 12、Android12--常见控件(一) 13、Android13--常见控件(二) 14、Android14--Adapter 15、Android15--ListView 16、Android16--自定义控件 18、Android18--...
上一篇文章已经介绍了单元测试的作用和简单示例,如果不了解的读者可以先阅读上一篇[ Android单元测试-作用以及简单示例](http://blog.csdn.net/double2hao/article/details/77159380)。 这篇文章主要介绍常见的...
二、布局设计 在 Android 项目中,布局设计是非常重要的一步。布局设计决定了应用程序的用户界面。常用的布局方式有 LinearLayout、RelativeLayout、TableLayout 等。在本实例中,我们使用了 LinearLayout 进行布局...
android常见Activity+Fragment标签页布局源码,应用主页常见布局
activity中动态加载布局,有时候很常用,但是总是想不起来这种方法,所以写个例子和大家分享
android 在Activity里显示列表 ListView的布局
Android4.0入门之Activity返回参数: 开发流程梳理: 1.对界面进行布局(在layout目录下配置每个Activity对应的xml) 2.书写Activity类,获取控件、添加时间(新增Activity后,切记到配置Activity文件中去注册) ...
03-Android UI设计与Activity组件_实验06-Android UI设计与常用布局.pdf、实验07-Android组件.pdf、实验08-Android UI&Activity实例.pdf、实验09-Android RecyclerView动态布局加载.pdf; 04-Android基础功能程序...
"Activity 的简单布局切换" Activity 是 Android 操作系统中的一种基本组件,负责处理用户交互和界面显示。一个 Activity 可以包含多个布局页面,并且可以在不同的情况下进行切换。 1. Activity 的基本概念 ...
import android.app.Activity; import android.os.Bundle; public class Main extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle ...
NULL 博文链接:https://byandby.iteye.com/blog/830420
NULL 博文链接:https://byandby.iteye.com/blog/829512
掌握将组件值提交到下一个Activity活动的方法 二.实验环境 JDK的版本: "1.8.0_40" IDE: eclipse 4.6.1 模拟器: 夜神模拟器 三.实验内容 1. 补充完成下例空缺处,完成注册界面、部门列表框、 单击确定检查 提交...
(框架)Android例子源码——tabhost+activity+slidingMenu仿新浪微博布局.zip
详情见博客:https://blog.csdn.net/qq_20785431/article/details/100519075