任何编程学习起步均是HelloWorld,作为稍有>net编程经验的我们来说就跳过这步吧,咱们且从简单登录界面开始。先看看效果:

一、准备知识:

1. 安卓环境:安装好JDK,直接去官网下载ADT-bundle集成包后更新即可使用。

2. 项目目录:一张图说明一切

二、页面布局:

还是一幅图说明一切

那么这个界面的布局如何呢?

<LinearLayout >最外边的DIV,用的是线性布局,方向是垂直

    <TextView/>就是上图“初始用户名。。。”这几个字所在Lable

    <LinearLayout >里面的DIV,水平布局
<TextView/>用户名Lable
<EditText/>用户名TextBox
</LinearLayout> <LinearLayout>里面的DIV,水平布局
<TextView/>密码Lable
<EditText/>密码TextBox
</LinearLayout> <Button/>登录按钮 </LinearLayout>

上图一看,就会一半,下来一个一个看:

1. 最外层DIV:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" android:layout_margin="5dip" >

定义宽高的停靠方式,有

fill_parent、match_parent:是一样的,为了兼容低版本,建议使用fill_parent

设置布局/控件为fill_parent将强制性让它布满整个屏幕或填满父控件的空白

wrap_content:被内容撑大,刚好能显示下内容为止

Orientation:排列方式,vertical垂直,默认是HORIZONTAL水平

2. 文本框:

<TextView
android:id="@+id/lbl_LoginPass"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/lbl_LoginPass_Text"
android:textSize="15.0sp" />

这里出现了两个未知属性:

@+id/lbl_LoginPass和@string/lbl_LoginPass_Text

其实完全可以直接写:

android:text="用户名"

系统会提示这是硬编码,建议改写(汗,写了这么多年硬编码),他意思是这里仅仅引用字典中一个变量的名称,具体的值在字典中去维护,那么字典在哪里呢?

Res/Values/String.xml中维护了这个字典:

<resources>
<string name="app_name">登录DEMO</string>
<string name="action_settings">Settings</string>
<string name="lbl_LoginName">用户名:</string>
<string name="lbl_LoginPass_Text">密 码:</string>
<string name="btn_login">开始登陆</string>
</resources>

这里编码规范得注意一下了:假如控件ID为lbl_LoginPass,则他的字典名应该为lbl_LoginPass_Text为了防止多个页面的字典名重复建议最好加上页面前缀,如Login_lbl_LoginPass_Text

完整代码如下:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" android:layout_margin="5dip" >
<TextView
android:id="@+id/form_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="初始用户名和密码都是123" />
<LinearLayout
android:id="@+id/layout_login_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="5.0dip"
android:layout_marginTop="10.0dip"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/lbl_LoginName" />
<EditText
android:id="@+id/txt_login_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="15.0sp" />
</LinearLayout> <LinearLayout
android:id="@+id/login_pwd_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/layout_login_name"
android:layout_centerHorizontal="true"
android:layout_margin="5.0dip"
android:orientation="horizontal" >
<TextView
android:id="@+id/login_pass_edit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/lbl_LoginPass"
android:textSize="15.0sp" /> <EditText
android:id="@+id/txt_login_pwd"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:password="true"
android:textSize="15.0sp" />
</LinearLayout> <Button
android:id="@+id/btn_login"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:onClick="btn_click"
android:text="登陆" />
</LinearLayout>

3. 页面后台
打开页面对应的后台代码:MainActivity.java

手动实现按钮的点击事件:

    public void btn_click(View v)
{
TextView lblInfo=(TextView)findViewById(R.id.form_title); EditText txt_login_name=(EditText)findViewById(R.id.txt_login_name);
EditText txt_login_pass=(EditText)findViewById(R.id.txt_login_pwd);
String loginName=txt_login_name.getText().toString().trim();
String loginPass=txt_login_pass.getText().toString().trim();
if(loginPass.equals("")&&loginName.equals(""))
{
lblInfo.setText("登录成功!");
}
else
{
lblInfo.setText("登录失败!");
} }

其实这些倒没啥说的一看名字就知道啥意思。

.Net程序员安卓学习之路1:登陆界面的更多相关文章

  1. .Net程序员安卓学习之路4:使用xutils Get Post数据

    前面使用了一些网络上找来的类进行网络访问,后来发现了安卓开发中有一个国人写的类库xutils比较全面,也比较经典,故后续使用xutils类库进行记录. 本例服务端使用WCF来实现,写好的WCF服务端在 ...

  2. .Net程序员安卓学习之路6:等待条

    一般在需要访问网络或者长时间操作的时候避免界面无响应才使用:等待条 本例将实现一个无框架的等待条,效果如下: 点击后,使线程Sleep5秒,就出现如下效果: 实现代码如: private Progre ...

  3. .Net程序员安卓学习之路5:使用xutils注入View和事件以及图片的显示

    xUtils注入和图片显示 一.xUtils注入 引用官方介绍: ViewUtils模块: •android中的ioc框架,完全注解方式就可以进行UI,资源和事件绑定: •新的事件绑定方式,使用混淆工 ...

  4. .Net程序员安卓学习之路3:Post数据给网络API

    本例我们实现一次真正的网络交互,将数据POST到API,然后接收服务器的返回值进行处理,同时引入自定义类型和传说中阿里的FastJson. 实现思路如: 1. 在API端接收客户POST的数据还原成对 ...

  5. .Net程序员安卓学习之路2:访问网络API

    做应用型的APP肯定是要和网络交互的,那么本节就来实战一把Android访问网络API,还是使用上节的DEMO: 一.准备API: 一般都采用Json作为数据交换格式,目前各种语言均能输出Json串. ...

  6. zz 游戏程序员的学习之路(中文版)

    游戏程序员的学习之路(中文版) Milo Yip · 1 天前 感谢 @楚天阔(tkchu)编写脚本及整理中文译本数据,自动从英文版生成中文版,SVG / PDF 版本中的书籍图片现在链接至豆瓣页面. ...

  7. GJM : 游戏程序员的学习之路

    原文作者:miloyip  原帖地址:http://gad.qq.com/article/detail/7180681 原帖备注:版权所有,禁止匿名转载:禁止商业使用:禁止个人使用. 腾讯前端技术总监 ...

  8. 五年.net程序员Java学习之路

    大学毕业后笔者进入一家外企,做企业CRM系统开发,那时候开发效率最高的高级程序语言,毫无疑问是C#.恰逢公司也在扩张,招聘了不少.net程序员,笔者作为应届生,也乐呵呵的加入到.net程序员行列中. ...

  9. 2017PHP程序员的进阶之路

    2017PHP程序员的进阶之路 又是一年毕业季,可能会有好多毕业生即将进入开发这个圈子,踏上码农这个不归路.根据这些年在开发圈子总结的LNMP程序猿发展轨迹,结合个人经验体会,总结出很多程序员对未来的 ...

随机推荐

  1. BZOJ4299 : Codechef FRBSUM

    若$[0,i]$的数都可以得到,那么$[1,所有不大于i+1的数的和]$的数都可以得到. 如此暴力枚举答案,用可持久化线段树支持查询,因为每次数字至少翻一倍,所以复杂度为$O(m\log^2n)$. ...

  2. 【POJ】2318 TOYS(计算几何基础+暴力)

    http://poj.org/problem?id=2318 第一次完全是$O(n^2)$的暴力为什么被卡了-QAQ(一定是常数太大了...) 后来排序了下点然后单调搞了搞..(然而还是可以随便造出让 ...

  3. 安装win7 ubuntu双系统

    http://www.cnblogs.com/shengansong/archive/2011/10/23/2221716.html http://www.cnblogs.com/shenganson ...

  4. Javascript Math ceil()、floor()、round()三个函数的区别

    Round是四舍五入的...Ceiling是向上取整..float是向下取整. ceil():将小数部分一律向整数部分进位. 如: Math.ceil(12.2)//返回13 Math.ceil(12 ...

  5. 关于iOS测试机个数上限的详细规则

    关于iOS测试机个数上限的详细规则 前言 公司的iOS测试机快达到苹果规定的100个上限了,而因为the new iPad新出,我们需要新的quota来测试新iPad,所以就仔细研究了一下苹果关于10 ...

  6. serv-u and hway3.0

    一个非常好用的su提权脚本,在支持php的环境下,目录可读可写,基本秒杀. <? //HWay && Serv-U by r00t //r00t@007team.net //ww ...

  7. android开发事件监听

    第一种:匿名内部类作为事件监听器类 大部分时候,事件处理器都没有什么利用价值(可利用代码通常都被抽象成了业务逻辑方法),因此大部分事件监听器只是临时使用一次,所以使用匿名内部类形式的事件监听器更合适, ...

  8. MySQL 数据库设计 笔记与总结(4)维护优化

    [维护和优化的工作] ① 维护数据字典 ② 维护索引 ③ 维护表结构 ④ 在适当的时候对表进行水平拆分或垂直拆分 [维护数据字典] a 使用第三方工具对数据字典进行维护 b 利用数据库本身的备注字段来 ...

  9. Linux提示no crontab for root的解决办法

    Linux提示no crontab for root的解决办法 安装crontab:yum install crontabs 说明:/sbin/service crond start //启动服务/s ...

  10. MySQL 数据库性能优化之SQL优化

    前言 有人反馈之前几篇文章过于理论缺少实际操作细节,这篇文章就多一些可操作性的内容吧. 注:这篇文章是以 MySQL 为背景,很多内容同时适用于其他关系型数据库,需要有一些索引知识为基础. 优化目标 ...