呵呵今天终于写了两个跳转的actity的页面,感觉还可以,呵呵 好了,下面记录下我今天晚上的android实例:
开发环境:windowXP、androidSDK2.2、eclipse3.4(关于环境配置请看我的另外一篇博客文章介绍)
项目名称:layout
应用名称:layout
包名:com.eoeandroid.layout
首先新建一个主actity名称:ActivityMain.java
package com.eoeandroid.layout;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class ActivityMain extends Activity {
Button button0;
//配置的监听程序
OnClickListener listener0= new OnClickListener() {
public void onClick(View v){
//通过Intent这个类能够使我们从本页面跳转到ActivityRelativeLayout这个类里面
Intent intent1 =new Intent(ActivityMain.this,ActivityRelativeLayout.class);
startActivity(intent1);
}
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
button0 = (Button) findViewById(R.id.button0);
//为butonO按钮注册监听程序
button0.setOnClickListener(listener0);
}
}
下一步新建一个跳转到的actity :ActivityRelativeLayout.java
package com.eoeandroid.layout;
import android.app.Activity;
import android.os.Bundle;
public class ActivityRelativeLayout extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//通过这个方法显示:relative_layout.xml配置的界面
setContentView(R.layout.relative_layout);
}
}
上面的类已经建完成了,下面就需要构建UI层,android系统开发,和以前的javase还不太一样就是说:android的界面一般通常情况下界面都是通过xml的配置显示效果界面出来,当然也可以用java代码编写出来,这要看个人的需要:
首先配置主屏幕显示的界面也就是ActivityMain.java的界面(ActivityMain.java只是将按钮注册了一个监听但没有显示):ActivityMain默认的main.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">
<Button android:id="@+id/button0" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="我来了" />
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content" android:text="@string/hello" />
</LinearLayout>
-------------------------------------------------------------
上面的XML的配置效果是:一个按钮,按钮上面文字是:“我来了”,按钮下面有一行字“HelloWorld Actitymain”
下面接添加配置需要转到的页面的xml配置文件:
relative_layout.xml
----------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView android:id="@+id/label" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:text="请输入用户名:" />
<!--
这个EditText放置在上边id为label的TextView的下边
-->
<EditText android:id="@+id/entry" android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@android:drawable/editbox_background"
android:layout_below="@id/label" />
<!--
取消按钮和容器的右边齐平,并且设置左边的边距为10dip
-->
<Button android:id="@+id/cancel" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_below="@id/entry"
android:layout_alignParentRight="true"
android:layout_marginLeft="10dip" android:text="取消" />
<!--
确定按钮在取消按钮的左侧,并且和取消按钮的高度齐平
-->
<Button android:id="@+id/ok" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/cancel"
android:layout_alignTop="@id/cancel" android:text="确定" />
</RelativeLayout>
-----------------------------------------------------------------
上面的两个配置是两个页面的的UI的XML配置文件,现在还需要将两个界面的Actity的java类都注册到android系统中(当然这时我自己的理解),这时还需要配置一下默认的一个文件叫:AndroidManifest.xml
----------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.eoeandroid.layout"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".ActivityMain"
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="ActivityRelativeLayout"></activity>
</application>
<uses-sdk android:minSdkVersion="8" />
</manifest>
----------------------------------------------------------------
以上就是完整的一个实例了,已经经过我的测验,当然这个代码是参照了android开发与入门的代码,看了几天一会查资料,一会问别人呵呵终于算是理解了一点点,不管理解的到底对不对,最起码按照我的理解算是把一个完整的小例子给跑了起来,呵呵
分享到:
相关推荐
Android学习实例包,包含8个实例,是学习Android移动开发的必备利器,包含:1、Android中滑屏实现 2、ListView下拉更新功能CustomListView 3、listview下拉刷新 4、Android仿iPhone滚动控件源码 5、Android自定义...
Android移动开发案例详解配有几个移动开发实例,有条件的也可以在电脑上进行调试。
Android移动开发实例包002是学习Android开发的利器,包含:1、条形码、二维码扫描、生成Demo 2、android-整体UI设计-滑动导航栏+滚动页面 3、CityWeather 4、FileManager 5、MobileMap 6、MusicPlayer 7、MyContacts...
Android 移动开发基础教程(慕课版)源代码,刘刚主编,本书详细讲解了Android软件开发的基本方法和常用技能。全书分为9章,通过大量实例展示相关技术与技巧,最后通过完整项目的开发实现过程来提高读者的综合开发...
android移动应用与开发各章节中的实例
Android安卓应用程序开发实例源码合集: 7个经典Android应用程序实例源代码.rar Android 培训--18个单项功能实例源码.rar Android 小项目开发示例大全--20个通用具体应用程序实例源码.rar Android 文件下载功能Java...
第1章 UI布局开发实例集锦 1 实例001: 使用线性布局(LinearLayout) 来布局屏幕 1 实例002: 使用相对布局(RelativeLayout)来布局屏幕 3 实例003: 使用表格布局(TableLayout) 来布局屏幕 5 实例004: 使用...
Android移动开发案例教程源代码第1-2章所有,涵盖与教程相对应的所有源码内容
Android开发实例大全 第2版
其中,第1~3章是基础篇,包括Android技术概述、Android网络开发技术基础、创建移动Web的方法;第4~13章是HTML 5篇,讲解了在Android中使用HTML 5技术设计移动Web网页的基本知识,包括HTML 5架构、基本元素、表单...
Android移动平台开发-实验报告
android游戏开发原创实例 人物移动+子弹+跳高
《Android移动应用开发从入门到精通》由浅入深地全面讲解了基于Android系统的软件开发,以Andmid 2.3版本作为主要的SDK版本。本书涉及面广,涵盖了Android系统几乎所有的应用领域,并详细介绍了Android系统常用工具...
《Android移动应用开发(第3版)卷Ⅰ:基础篇》涵盖了作者数年来在移动开发领域所积累的经验,以及成功进行移动项目开发所需的全部概念和实用技术,包括移动开发过程与传统软件开发的区别,还包括帮助你节约宝贵时间和...
第11 章Android游戏开发实例 11.1 手机游戏开发简介 11.2 游戏框架设计 11.3 地图设计 11.4 主角设计 11.5 图层管理器 11.6 游戏音效 11.7 游戏存档 11.8 小结 第四部分 高级篇 第12章 AndroidOpenGL开发 基础 12.1...
Android应用开发基础与实例
Android移动应用开发之使用异步调用进度条的简单实例使用AsyncTask来实现0积分放心下载!
《移动平台开发书库:Android项目开发详解》涵盖了Android前端界面开发、Activity java程序的开发以及ASP后台技术开发等内容,强调了Android与后台数据通信技术、XML解析技术、数据存储技术以及与Android前端配套的...
Android平台是Google推出的新一代智能手机平台。本文深入阐述了Android平台的系统架构、APJ结构、应用程序类型:分析了Android平台相对其他手机平台的特色之...并结合实例介绍了Android平台的开发环境配置和编程方法。
Android移动开发案例详解代码,包括十一个章节