.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应用可不 ...
随机推荐
- Google的Java经常使用类库 Guava
Guava 中文是石榴的意思,该项目是 Google 的一个开源项目,包括很多 Google 核心的 Java 经常使用库. 1. 基本工具 [Basic utilities] 让使用Java ...
- Principle of Computing (Python)学习笔记(5) BFS Searching + Zombie Apocalypse
1 Generators Generator和list comprehension非常类似 Generators are a kind of iterator that are defined l ...
- google浙大招聘笔试题 师兄只能帮你到这儿了
google浙大招聘笔试题 一.单选1.80x86中,十进制数-3用16位二进制数表示为?00100002.假定符号-.*.$分别代表减法.乘法和指数运算,且 1)三个运算符优先级顺序是:-最高,*其 ...
- Ajax - 手册
一.Ajax概述: 1.Ajax(Asynchronous JavaScript and XML):异步的JavaScript和XML 2.Ajax不是某种语言,而是在现实网页的时候一种局 ...
- linux命令:ftp
1. 登录: ftp IP_ADDR : 根据提示输入USER_NAME PASS_WORD 或: ftp -i -n IP_ADDR user USER_NAME PASS ...
- 重操JS旧业第十弹:闭包
闭包是js最难理解,也是最蛋疼的一个名词,仿佛只可意会不可言传一样,有人说闭包说白了就是函数嵌套,也有人说闭包就是函数能够访问函数外部的变量,而内部的外部访问不了: 貌似都非常有道理,其实仔细想来只不 ...
- 不包含SDK头文件, 补全API定义
/// @file main.cpp /// @brief 不包含SDK头文件, 补全API定义 #ifdef __cplusplus extern "C" { #endif /* ...
- 基于visual Studio2013解决面试题之0506取和为m的可能组合
题目
- 基于visual Studio2013解决C语言竞赛题之1061最大值和次最大值
题目 解决代码及点评 /* 功能: 编写子函数, 求一维整型数组M[10]的最大值及次最大值(次最大值可能不存在). 主函数中输入10个整数, 然后调用上述子函数, 若次最大值存在, ...
- netduino第一步,环境配置
在netduino.com的官网介绍下,我很快就入门,现在的最新netduino的版本是4.3,但4.3是运行在win8下的,在codeplex.net上有,大部分人还使用的是win7,因此我现在采用 ...