.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应用可不 ...
随机推荐
- C++中vector的实现
注意几点: 分配内存不要使用new和delete,由于new的同一时候就把对象构造了.而我们须要的是原始内存. 所以应该使用标准库提供的allocator类来实现内存的控制.当然也能够重载ope ...
- 时间戳timestamp
1 时间戳 数据库中自动生成的 唯一的 二进制的数据,通常用作给数据表的行添加版本戳的机制. timestamp与时间和日期无关. timestamp存储大小为8字节. 一个数据表只能有一个times ...
- Java多线程实现生产者消费者延伸问题
在操作系统中有一类问题被称为生产者消费者问题:意为,有数个生产者生产产品,有数个消费者消费产品,他们共享一定数量的缓存. 这里用java多线程编程,实现生产者消费者问题的一种延伸,橘子苹果问题. 题目 ...
- 基于visual Studio2013解决C语言竞赛题之1053洗牌
题目 解决代码及点评 /* 功能:洗扑克牌.将54张牌分别编号为1,2,-,54号,并放在数组M中. 洗牌方法如下:产生[1,54]区间内的一个随机数K,将M[1]与M[K]交换: ...
- 碰撞回避算法(一) Velocity Obstacle
碰撞回避是机器人导航,游戏AI等领域的基础课题.几十年来,有很多算法被提出.注意这里主要指的是局部的碰撞回避算法.尽管和全局的路径规划算法(A*算法等)有千丝万缕的联系.可是还是有所不同的(局部的碰撞 ...
- 浅谈sqlldr
1.安装oracle sqlldr 2.配置sqlldr环境 3java代码的实现 在windows下面sqlldr: sqlldr = “cmd /c start D:/oracle/produ ...
- [课堂实践与项目]IOS只能进行简单的加减乘除的没有优先级的计算器
// // LCViewController.m // calculator // // Created by lichan on 13-12-3. // Copyright (c) 2013年 co ...
- Window7下安装openssl完整版(亲测实现)
安装环境: 操作系统:window7(64位) C++编译器:VS2010 -------------------------------------------------------------- ...
- gcc中__attribute__ ((constructor(101)))做成.a库成功链接
1.cpp:------------------------------------------------ #include int test() __attribute__ ((construct ...
- Javascript实现简单的富文本编辑器
<span style="font-size:14px;"><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 T ...