接下来我们介绍的登陆页面布局,在本节中,我们看一下注册页面布局,页面布局大同小异,来一起熟悉下基本控件的使用方法。

效果图:

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)注册页面布局的更多相关文章

  1. .Net程序猿乐Android发展---(1)环境结构

    对于没有接触Android人才发展,你可能会觉得Android更难以发展.接下来的一段时间,我们将了解Android开发的详细细节,主要是面对.NET程序猿,来看看.NET程序猿如何进行Android ...

  2. .Net程序猿玩转Android开发---(3)登陆页面布局

    这一节我们来看看登陆页面如何布局.对于刚接触到Android开发的童鞋来说.Android的布局感觉比較棘手.须要结合各种属性进行设置,接下来我们由点入面来 了解安卓中页面如何布局,登陆页面非常eas ...

  3. .Net程序猿乐Android发展---(10)框架布局FrameLayout

    帧布局FrameLayout中全部的控件都在界面的左上側,后绘制的空间会覆盖之前的控件.布局内控件以层叠方式显示,用在游戏开发方面可能多些. 1.层叠展示                 以下这个样例 ...

  4. android 开发 简单的页面布局

    package com.example.test; import android.app.Activity; import android.os.Bundle; import android.view ...

  5. CSharp程序员学Android开发---3.Android内部元素不填充BUG

    最近公司组织项目组成员开发一个Android项目的Demo,之前没有人有Andoid方面的开发经验,都是开发C#的. 虽说项目要求并不是很高,但是对于没有这方面经验的人来说,第一步是最困难的. 项目历 ...

  6. CSharp程序员学Android开发---2.个人总结的快捷键

    最近公司组织项目组成员开发一个Android项目的Demo,之前没有人有Andoid方面的开发经验,都是开发C#的. 虽说项目要求并不是很高,但是对于没有这方面经验的人来说,第一步是最困难的. 项目历 ...

  7. CSharp程序员学Android开发---1.初识AndriodIDE,掌握工具使用

    最近公司组织项目组成员开发一个Android项目的Demo,之前没有人有Andoid方面的开发经验,都是开发C#的. 虽说项目要求并不是很高,但是对于没有这方面经验的人来说,第一步是最困难的. 项目历 ...

  8. Java程序员转Android开发必读经验分享

    小编最近几日偷偷的发现部分Java程序员想转安卓开发,故此加紧补充知识,为大家搜集资料,积极整理前人的经验,希望可以给正处于困惑中的你,带来些许的帮助. 啰哩啰嗦的说说Java和Android程序的区 ...

  9. .net程序员业余Android开发赚点外快(介绍一下自己的经验)

    记得是11年10月份开始研究android的,当时还不会java,听说android比较火,自己也买了个垃圾android机,平时工作也不是特别忙,于是我就突发奇想,想试试做一下android应用可不 ...

随机推荐

  1. 再淡spring jdbc 连接池断开重连设置

    先看一段错误日志: ### Error querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConne ...

  2. EasyUI - DataGrid 组建 - [ 排序功能 ]

    效果: 红框的字段看,为设置了,列排序,向后台Post数据sort/order. 原理:向后台POST数据,sort/post数据. html代码: <table id="tab&qu ...

  3. Windows8 Metro快捷键 | Win8迷

    Windows8 Metro快捷键 | Win8迷   Win + Q : 打开 搜索面板 Win + C : 打开屏幕右侧的Charms简化菜单 Win + 空格 : 切换输入语言和键盘布局  

  4. 原始的js代码和jquery对比

    Even a task as simple as this can be complicated without jQuery at our disposal. In plain JavaScript ...

  5. Codeforces 484B Maximum Value(排序+二分)

    题目链接: http://codeforces.com/problemset/problem/484/B 题意: 求a[i]%a[j] (a[i]>a[j])的余数的最大值 分析: 要求余数的最 ...

  6. Servlet的学习(一)

    初识Servlet Servlet是一门专门用于开发动态web资源的技术,Sun公司在其API中提供了一个Servlet接口(当然,我们不会去直接实现这个接口,而是去继承其实现类会更好),因此,狭义的 ...

  7. boost:asio编译

    参考:http://hi.baidu.com/need_for_dream/blog/item/c14a28086a504c33e92488b5.html 环境: VS2010, boost1.38. ...

  8. POJ3678【错误总会让自己有收获的】

       首先我是的确确定了LRJ那个代码也是判断一个点的两种状态是否在一个连通分量内.    关于自己做的,自己又确定了一些,让自己那样先,比如说对于 3 6 1 AND这样3 6都已经确定的点,自己用 ...

  9. JAVA Useful Program(1)

    public static void main(String[] args){       //字符串有整型的相互转换          String str=String.valueOf(123); ...

  10. 自己写一个jqery的拖拽插件

    说实话,jQuery比原生的js好用多了,本来想用原生写的,也写出来的,仅仅是,感觉不像插件,所以用jQuery实现了一版. 实现的功能:能够指定拖拽的边界,在拖拽过程中,能够触发几个自己定义事件 先 ...