【声明】
欢迎转载,但请保留文章原始出处→_→
【正文】
两个小时的学习成果,对于我这种还没入门但渴望不断进步的初学者来说,是一种激励。通过自己一行一行的敲代码,实现了用相对布局做一个登陆界面的效果。
XML文件完整版代码如下:
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="20dp" >
android:id="@+id/lableView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="登陆界面" />
android:id="@+id/usernameView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/lableView"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:hint="username" />
android:id="@+id/passwordView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/usernameView"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:hint="password"
android:inputType="textPassword" />
android:id="@+id/cancleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/passwordView"
android:layout_alignParentRight="true"
android:text="取消" />
android:id="@+id/okButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@id/cancleButton"
android:layout_toLeftOf="@id/cancleButton"
android:text="确定" />
代码解释如下:
05行:设置整个RelativeLayout的内边距为20dp,给界面留白。
21、22行:让编辑框的左边对齐到父控件的左边,右边对齐到父控件的右边,这样一来,就刚好横向覆盖整个界面。
30行:将passwordView放到usernameView的下面,以保证二者的相对位置不变。
34行:输入密码时显示为星号,以保证密码的安全
41、42行:将“取消”按钮放到passwordView的下面,并贴齐到父控件的右边
50、51行:将“确定”按钮放到“取消”按钮的左边,并贴齐到“取消”按钮的下边,以保证二者的相对位置不变
最终在手机上运行后,显示效果如下:
我的公众号
想学习代码之外的软技能?不妨关注我的微信公众号:生命团队(id:vitateam)。
扫一扫,你将发现另一个全新的世界,而这将是一场美丽的意外:
Android UI组件----ListView列表控件详解
[声明] 欢迎转载,但请保留文章原始出处→_→ 生命壹号:http://www.cnblogs.com/smyhvae/ 文章来源:http://www.cnblogs.com/smyhvae/p/3 ...
Android UI基础之五大布局
Android UI基础之五大布局 Android的界面是有布局和组件协同完成的,布局好比是建筑里的框架,而组件则相当于建筑里的砖瓦.组件按照布局的要求依次排列,就组成了用户所看见的界面.Andro ...
Android 高级UI设计笔记08:Android开发者常用的7款Android UI组件(转载)
Android开发是目前最热门的移动开发技术之一,随着开发者的不断努力和Android社区的进步,Android开发技术已经日趋成熟,当然,在Android开源社区中也涌现了很多不错的开源UI项目,它 ...
Android UI组件:布局管理器
为了更好的管理Android应用的用户界面中的组件,Android提供了布局管理器.通过使用布局管理器,Android应用的图形用户界面具有良好的平台无关性.通常,推荐使用布局管理器来管理组件的分布. ...
Android——四大组件、六大布局、五大存储
一.android四大组件 (一)android四大组件详解 Android四大组件分别为activity.service.content provider.broadcast receiver. 1 ...
这是一个比较全的Android UI 组件