- 浏览: 73046 次
- 性别:
- 来自: 北京
最近访客 更多访客>>
文章分类
- 全部博客 (86)
- Java_Develop (6)
- Develop about Android (11)
- Develop about C (3)
- Develop about C++ (13)
- Develop about Objective-C (8)
- Develop about XML&DOM4J (6)
- Develop about JSP (7)
- Develop about Servlet (14)
- develop about MySql (4)
- Develop about Java_Socket (1)
- Develop about Java_Thread (4)
- Develop about IOS (8)
最新评论
-
eric_weitm:
在效率本身上而言,引用也有优势。另外,在编译器实现时,指针的传 ...
C++中的 引用和指针区别
今天讲解的内容是UI组件的TextView组件和EditView组件。
通过今天的作业提现各种组件的用法并介绍通用属性。
作业;
上图为今天的作业,要求用Android实现上述页面布局,不用实现功能。
首先,我写了一下string.xml文件,把所有字符串都写到里面,代码如下:
<?xml version="1.0"encoding="utf-8"?>
<resources>
<stringname="title">杨博的登录作业</string>
<stringname="mail">电子邮件:</string>
<stringname="user">用户名:</string>
<stringname="pass">密码:</string>
<stringname="repass">确认密码:</string>
<stringname="num">验证码:</string>
<stringname="really"><a href="#">看不清?</a></string>
<stringname="again"><a href="#">换一个</a></string>
<stringname="xieyi">我已阅读并同意《凤凰使用协议》</string>
<stringname="sub"><a href="#">提交注册</a></string>
</resources>
写好string.xml文件后,我们需要写布局文件。对于这个提交注册表单,我们需要用到的布局方式不是单一的,而是多种嵌套。因为,如果我们用线性布局,每行或列只能放一个组件,不能满足上图要求。用相对布局显得太繁琐。用表格布局,前四行可以完成,但验证码这一行就有点困难了,所以综述这点,我用了表格布局+相对布局的方式。
布局文件如下:
<?xml version="1.0"encoding="utf-8"?>
<TableLayoutxmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/girl"
>
<!-- 电子邮件 -->
<TableRow>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/mail"
android:textSize="20dp"
android:textStyle="bold"/>
<EditText
android:layout_width="200dp"
android:layout_height="wrap_content"
android:id="@+id/mail"/>
</TableRow>
<!-- 用户名 -->
<TableRow>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/user"
android:textSize="20dp"
android:textStyle="bold"/>
<EditText
android:layout_width="200dp"
android:layout_height="wrap_content"
android:id="@+id/user"/>
</TableRow>
<!-- 密码 -->
<TableRow>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/pass"
android:textSize="20dp"
android:textStyle="bold"/>
<EditText
android:layout_width="200dp"
android:layout_height="wrap_content"
android:password="true"
android:id="@+id/pass"/>
</TableRow>
<!-- 确认密码 -->
<TableRow>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/repass"
android:textSize="20dp"
android:textStyle="bold"/>
<EditText
android:layout_width="200dp"
android:layout_height="wrap_content"
android:password="true"
android:id="@+id/repass"/>
</TableRow>
<RelativeLayout >
<!-- 验证码 -->
<TextView
android:id="@+id/num_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:paddingRight="20dp"
android:paddingTop="15dp"
android:text="@string/num"
android:textSize="20dp"
android:textStyle="bold" />
<!-- 验证码输入框 -->
<EditText
android:id="@+id/num"
android:layout_width="60dp"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/num_tv" >
<requestFocus />
</EditText>
<!-- 验证码图片 -->
<TextView
android:id="@+id/pic"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_toRightOf="@id/num"
android:background="@drawable/num" />
<!-- “看不清” -->
<TextView
android:id="@+id/really"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_toRightOf="@id/pic"
android:text="@string/really"
android:textSize="15dp"
android:textStyle="bold"/>
<!-- “换一个” -->
<TextView
android:id="@+id/again"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="@string/again"
android:textSize="15dp"
android:textStyle="bold"
android:layout_toRightOf="@id/really" />
<!--协议复选框 -->
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/xieyi"
android:layout_alignParentBottom="@id/num_tv"
android:gravity="center"
android:id="@+id/xieyi"
android:layout_marginTop="45dp"/>
<!--提交注册 -->
<Button
android:layout_width="80dp"
android:layout_height="40dp"
android:text="@string/sub"
android:layout_alignParentBottom="@id/xieyi"
android:gravity="center"
android:layout_marginTop="110dp"
android:textColor="#FFFFFF"
android:background="#FFCC66"
android:layout_marginLeft="120dp"
/>
</RelativeLayout>
</TableLayout>
写布局文件时候,我们可以熟知命名空间是:Android,所以我们必须在每个属性添加前都写上Android。每行都写了一组<TextView>和<EditView>组件,前四行都用标准的表格布局显示。验证码这行用的是线性布局,在插入图片的时候遇到了问题,不过已经解决了,现在总结一下:
插入图片的方法有多种,其中一中是写一个<TextView>组件,然后写定长宽,写一个:Android:background=””这条属性就是定义图片的,或者说是背景图片,我们在双引号中可以加入ID,drawable等等,实现我们想要的效果;
或者是添加一个<imageView>组件,在属性中指定长宽和背景图片即可。
我在调整图片边距的时候遇到了一些问题,说白了还是对以前知识掌握的不够扎实,就是外边距和内边距的区别,事由是这样的:我创建了一个<Button>组件,想让按钮的左边距不为0dp,于是,我就设置了gravity这个属性的Center值,但结果是按钮的文字有了效果,但按钮本身没有变化,最终通过改变margin-left的值解决了这个问题。
还有就是,无论需要改变什么组件的背景图或者插入图片都可以使用通用的属性:Android:background=””,这个属性来实现,本例子中有对屏幕的背景颜色和按钮的背景色做出实例化改变。
最终的实现效果如下:
发表评论
-
Android开发——概述及环境搭建
2011-12-05 21:25 636今天开始学习安卓手机软件开发,首先介绍一下Android: ... -
Android开发之:第一个应用程序及工程文件及结构详解
2011-12-06 17:10 780Android开发之:第一个应用程序及工程文件及结构详解 ... -
Android开发——手机拨号程序实现
2011-12-06 19:50 927在上一篇文章中,我们实现了第一个程序:helloWorld,并 ... -
Android开发——关于onCreate的解读
2011-12-06 20:34 824当我们创建好一个Android项目后,打开src下的java ... -
Android开发——布局详解(上)
2011-12-07 16:54 708Android开发——布局详解(上) 在昨天的学习中, ... -
多种方式实现Android页面布局的切换
2011-12-08 18:07 1430多种方式实现页面切换 今天老师留的作业如题,要求用三种方 ... -
Android开发——Android生命周期
2011-12-10 20:11 606Activity的三种状态: ... -
Android开发——菜单小问题解决
2011-12-12 20:47 787在写菜单项的时候发现一个不知道的知识点,问题是这样产生的。写好 ... -
Android开发——跟随手指的小球实现
2012-01-11 14:13 847今天要实现的是一个跟随手指的小球,说白了就是让小球按着手指滑动 ... -
Android开发——实现点击图片切换效果
2012-01-11 14:15 934在资源中添加5张图片,重命名为a-e。 实现java代码如下 ...
相关推荐
安卓Android源码——ui开发类库示例源码.zip
安卓Android源码——UI界面源码.zip
Android源码——UI界面源码.zip
Android源码——UI界面源码.rar
安卓Android源码——UI设计之 仿做蘑菇街UI设计 源码.zip
Android源码——ui开发类库示例源码_new_19.7z
Android源码——ui开发类库示例源码_new_19.zip
Android源码——UI界面源码.7z
安卓Android源码——UI界面漂亮的天气预报源码.zip
Android源码——UI界面漂亮的天气预报源码.zip
Android开发笔记,UI基础编程,PDF文档。
【Cocos Creator实战教程(8)】——UI组件(2)ProgressBar 组件
【Cocos Creator实战教程(7)】——UI组件(1)ScrollView 组件
【Cocos Creator实战教程(9)】——UI组件(3)Toggle 组件
【Cocos Creator实战教程(10)】——UI组件(4)Slider 组件
Android源码——UI界面漂亮的天气预报源码.7z
TextView(标签文本) EditText(文本输入框) Button(按钮) ImageButton(图像按钮) ToggleButton(开关按钮) RadioButton(单选按钮) Progressbar(进度条) Checkbox(检查框) SeekBar(滑动条) ...