2014-08-18 22:37:14|?次阅读|上传:huigezrx【已有?条评论】发表评论
关键词:Java, Android, 界面设计, 移动应用|来源:唯设编程网
上面的代码对于某些应用程序来讲已经足够了,这些应用程序只需要简单地从一个Activity 跳转至下一个。当然,你也可以通过一种更为稳健的方式使用Intent 机制。例如,你可以使用Intent 结构在Activity 之间传送数据。
这一节,我们只介绍怎样在Activity内启动另外一个Activity,并不传递参数。
程序启动的第一个界面如下:

点击下一页后,启动另一个Activity:

首先看看我们连个Activity对应的XML布局代码,第一个Activity对应的布局文件是main_activity.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"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="这是第一个测试用的activity,点击“下一页”切换到另一个Activity"
/>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="下一页"
/>
</LinearLayout>
第二个Activity对应的布局文件(mylayout.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"
android:background="#ffffff"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="这是第二个测试用的activity,请点击“上一页”返回操作"
/>
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="上一页"
/>
</LinearLayout>