.Net程序猿乐Android开发---(4)注册页面布局
接下来我们介绍的登陆页面布局,在本节中,我们看一下注册页面布局,页面布局大同小异,来一起熟悉下基本控件的使用方法。
效果图:

1.加入注冊页面
右键选中layout目录,加入注冊页面.例如以下图



点击完毕,页面加入完毕. 在页面中加入控件。XML代码例如以下
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"> <LinearLayout android:layout_width="fill_parent" android:layout_weight="0.9" android:layout_height="fill_parent">
</LinearLayout> <LinearLayout
android:layout_width="fill_parent"
android:layout_weight="0.1"
android:orientation="vertical"
android:layout_height="fill_parent"> <LinearLayout
android:layout_marginLeft="10px"
android:layout_marginRight="10px"
android:gravity="center"
android:layout_width="fill_parent"
android:orientation="horizontal"
android:layout_height="wrap_content"> <TextView android:textSize="8pt"
android:text="username"
android:layout_weight="0.75"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</TextView>
<EditText
android:layout_weight="0.25"
android:layout_width="fill_parent"
android:text="请输入username"
android:layout_height="wrap_content">
</EditText> </LinearLayout> <LinearLayout
android:layout_marginLeft="10px"
android:layout_marginRight="10px"
android:gravity="center"
android:layout_width="fill_parent"
android:orientation="horizontal"
android:layout_height="wrap_content"> <TextView android:textSize="8pt"
android:text="password"
android:layout_weight="0.75"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</TextView> <EditText android:layout_weight="0.25" android:layout_width="fill_parent" android:password="true" android:text="请输入password" android:layout_height="wrap_content">
</EditText> </LinearLayout> <LinearLayout
android:layout_marginLeft="10px"
android:layout_marginRight="10px"
android:gravity="center"
android:layout_width="fill_parent"
android:orientation="horizontal"
android:layout_height="wrap_content"> <TextView android:textSize="8pt"
android:text="确认password"
android:layout_weight="0.75"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</TextView> <EditText android:layout_weight="0.25" android:layout_width="fill_parent" android:password="true" android:text="请输入password" android:layout_height="wrap_content">
</EditText> </LinearLayout> <LinearLayout android:layout_marginLeft="10px" android:layout_marginRight="10px" android:gravity="center" android:layout_width="fill_parent" android:orientation="horizontal" android:layout_height="wrap_content">
<Button android:text="注冊 " android:textSize="9pt" android:layout_width="fill_parent" android:layout_height="wrap_content"> </Button>
</LinearLayout> <LinearLayout
android:id="@+id/btnLogin"
android:layout_marginLeft="10px" android:layout_marginRight="10px" android:gravity="center"
android:layout_width="fill_parent"
android:orientation="horizontal" android:layout_height="wrap_content">
<Button android:text="登录" android:textSize="9pt" android:layout_width="fill_parent" android:layout_height="wrap_content"> </Button>
</LinearLayout> </LinearLayout> </LinearLayout>
页面与后台代码关联
熟悉MVC的朋友都知道。MVC中页面与后台代码是分离的。Android中相同也是这种,这样做的优点是前台UI设计和后台程序开发彻底分离。
右键选中src目录中的包文件。加入后台类,例如以下图


点击完毕button后,我们成功的创建一个后台类。但此时后台类还没有与前台页面关联,我们须要重载类中的OnCreate方法,实现与页面关联
重载过程例如以下,在类文件空白处右键单击


点击OK,方法加入成功。
我们在OnCreate方法中加入setContentView(R.layout.register);来关联前台页面,
所有代码例如以下:
public class Register extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState)
{
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.register);
}
}
2.页面跳转
上一篇文章我们做了一个登陆页面,在登陆页面有一个注冊button,我们来看看假设从登陆页面跳转到注冊页面。
登陆页面代码例如以下:
package com.example.helloword; import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button; public class MainActivity extends Activity { private Button btnRegister;//声明注冊button
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnRegister=(Button)findViewById(R.id.btnRegeister);//找到页面中的注冊button
btnRegister.setOnClickListener(new OnClickListener() //绑定注冊button单击事件
{ @Override
public void onClick(View arg0) {
// button跳转
Intent intent = new Intent(MainActivity.this,Register.class);
startActivity(intent);
} });
} @Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
} }
注:每次在android项目中加入一个页面。都要在AndroidMainfest.xml中加入对应activity,代码例如以下
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.helloword.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity> <activity
android:name="com.example.helloword.Register">
</activity>
</application>
DEMO下载:http://download.csdn.net/detail/zx13525079024/8118723
.Net程序猿乐Android开发---(4)注册页面布局的更多相关文章
- .Net程序猿乐Android发展---(1)环境结构
对于没有接触Android人才发展,你可能会觉得Android更难以发展.接下来的一段时间,我们将了解Android开发的详细细节,主要是面对.NET程序猿,来看看.NET程序猿如何进行Android ...
- .Net程序猿玩转Android开发---(3)登陆页面布局
这一节我们来看看登陆页面如何布局.对于刚接触到Android开发的童鞋来说.Android的布局感觉比較棘手.须要结合各种属性进行设置,接下来我们由点入面来 了解安卓中页面如何布局,登陆页面非常eas ...
- .Net程序猿乐Android发展---(10)框架布局FrameLayout
帧布局FrameLayout中全部的控件都在界面的左上側,后绘制的空间会覆盖之前的控件.布局内控件以层叠方式显示,用在游戏开发方面可能多些. 1.层叠展示 以下这个样例 ...
- android 开发 简单的页面布局
package com.example.test; import android.app.Activity; import android.os.Bundle; import android.view ...
- CSharp程序员学Android开发---3.Android内部元素不填充BUG
最近公司组织项目组成员开发一个Android项目的Demo,之前没有人有Andoid方面的开发经验,都是开发C#的. 虽说项目要求并不是很高,但是对于没有这方面经验的人来说,第一步是最困难的. 项目历 ...
- CSharp程序员学Android开发---2.个人总结的快捷键
最近公司组织项目组成员开发一个Android项目的Demo,之前没有人有Andoid方面的开发经验,都是开发C#的. 虽说项目要求并不是很高,但是对于没有这方面经验的人来说,第一步是最困难的. 项目历 ...
- CSharp程序员学Android开发---1.初识AndriodIDE,掌握工具使用
最近公司组织项目组成员开发一个Android项目的Demo,之前没有人有Andoid方面的开发经验,都是开发C#的. 虽说项目要求并不是很高,但是对于没有这方面经验的人来说,第一步是最困难的. 项目历 ...
- Java程序员转Android开发必读经验分享
小编最近几日偷偷的发现部分Java程序员想转安卓开发,故此加紧补充知识,为大家搜集资料,积极整理前人的经验,希望可以给正处于困惑中的你,带来些许的帮助. 啰哩啰嗦的说说Java和Android程序的区 ...
- .net程序员业余Android开发赚点外快(介绍一下自己的经验)
记得是11年10月份开始研究android的,当时还不会java,听说android比较火,自己也买了个垃圾android机,平时工作也不是特别忙,于是我就突发奇想,想试试做一下android应用可不 ...
随机推荐
- ASP.NET - 后台获取按钮绑定的值CommandArgument
<asp:LinkButton runat="server" ID="resumelbtn" CommandArgument='<%# Eval(& ...
- PL/SQL(二):变量
变量 标识符定义 PL/SQL程序设计中的标识符定义与SQL的标识符定义的要求相同.要求和限制有: 个字符. )首字符必须为字母. )不区分大小写. )不能使用SQL保留字. )对标识符的命名最好遵循 ...
- Delphi中JSon SuperObject 使用:数据集与JSON对象互转
在delphi中,数据集是最常用数据存取方式.因此,必须建立JSON与TDataSet之间的互转关系,实现数据之间通讯与转换.值得注意的是,这只是普通的TDataset与JSON之间转换,由于CDS包 ...
- win2k/xp查看当前进程
win2k/xp查看当前进程 tasklist tasklist | find "关键字" 可以对结果进行过滤 关闭当前某个进程 taskkill /pid 程序的PID号码 wi ...
- javascript 回调函数应用
回调函数是什么在学习之前还真不知道js回调函数怎么使用及作用了,下面本文章把我在学习回调函数例子给各位同学介绍一下吧,有需了解的同学不防进入参考. 回调函数原理: 我现在出发,到了通知你”这是一个异步 ...
- boost计算随机数和计算crc32简单示例 - jwybobo2007的专栏 - 博客频道 - CSDN.NET
boost计算随机数和计算crc32简单示例 - jwybobo2007的专栏 - 博客频道 - CSDN.NET boost::crc_32_type crc32; crc32. ...
- Linux下经常使用的shell命令记录
硬件篇 CPU相关 lscpu #查看的是cpu的统计信息. cat /proc/cpuinfo #查看CPU信息具体信息,如每一个CPU的型号,主频等 内存相关 free -m #概要查看内存情况 ...
- 旧版QT的名称:qt-win-commercial-4.4.3-vc60.exe
qt-win-commercial-4.4.3-vc60.exeqt-vsaddin-collection-2.1.4.exeqt-win-commercial-4.4.3-v2005.exeqt-v ...
- Oracle 执行计划了的rows概念
alter session set statistics_level=all; select t1.* from t1,t2 where t1.id=t2.id and t1.id<3; sel ...
- win 7 设置防火墙例外的端口号, 让其域网中可以访问
背景,发布 一个tomcat下的website, 而发局域网可以访问. 这时,可以关闭防火墙:或者开启防火墙,并设置一个防火墙的入站规则,让身边的同事访问这个website. 设置方法:win 7 - ...