Android SDK 开发范例大全 ---3.8手机页面的转换
来源:互联网 发布:广州海度网络是培训吗 编辑:程序博客网 时间:2024/05/16 21:02
在网页的世界里,想要在两个网页间做转换,只要利用超链接(HyperLink)就可以实现,但在手机的世界,想要如何实现手机页面之间的转换呢?最简单的方法就是改变Activity的Layout!在这个范例里,将布局两个Layout,分别为Layout1(main.xml)与Layout2(mylayout.xml),默认加载的Layout为main.xml,且在Layout1中创建一个按钮,当单机按钮时,显示Layout2(mylayout,xml).同样地,在Layout2里也设计一个按钮,当单击第二个Layout的按钮之后,则显示回原来的Layout1.
src/com.helloworld/HelloWorldActivity.java
package com.helloworld;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class HelloworldActivity extends Activity {
/** Called when the activity is first created. */
private Button mButton1,mButton2;
private TextView mTextView1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mButton1 = (Button) findViewById(R.id.myButton1);
mButton1.setOnClickListener(new Button.OnClickListener(){
public void onClick(View v) {
// TODO Auto-generated method stub
jumpToLayout2();
}
});
}
public void jumpToLayout2() {
// TODO Auto-generated method stub
setContentView(R.layout.mylayout);
mButton2 = (Button) findViewById(R.id.myButton2);
mButton2.setOnClickListener(new Button.OnClickListener(){
public void onClick(View v) {
// TODO Auto-generated method stub
jumpToLayout1();
}
});
}
public void jumpToLayout1() {
// TODO Auto-generated method stub
setContentView(R.layout.main);
mButton1 = (Button) findViewById(R.id.myButton1);
mButton1.setOnClickListener(new Button.OnClickListener(){
public void onClick(View v) {
// TODO Auto-generated method stub
jumpToLayout2();
}
});
}
}
/res/layout/main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@drawable/white"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/myTextView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<Button
android:id="@+id/myButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_1" />
</LinearLayout>
/res/layout/mylayout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/myTextView02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hidi"
/>
<Button
android:id="@+id/myButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_2" />
</LinearLayout>
- Android SDK 开发范例大全 ---3.8手机页面的转换
- Android SDK开发范例大全 ---3.5取得手机屏幕的大小
- Android SDK 开发范例大全 ---3.7简单的按钮事件
- Google Android SDK开发范例大全
- Google Android SDK开发范例大全
- Google Android SDK开发范例大全
- 《Google android SDK开发范例大全》
- Google Android SDK开发范例大全 (一)
- Google Android SDK开发范例大全目录
- Android SDK 开发范例大全---3.2更改手机窗口画面底色
- Android SDK开发范例大全 ---3.3更改TextView颜色
- Android SDK开发范例大全 ---3.4置换TextView文字
- Android SDK 开发范例大全 ---3.9调用另一个Activity
- Android SDK开发范例大全 --3.6样式化的定型对象
- Android SDK 开发范例大全 ---3.10不同Activity之间的数据传递
- Android SDK 开发范例大全 ---3.12具有交互功能的对话框
- Android SDK 开发范例大全 ---3.13置换文字颜色的机关
- Android SDK 开发范例大全 ---3.14控制不同的文字字体
- getParameter和getAttribute的区别和使用范围
- WIFI之升级协议列表
- 苹果开发 手动内存管理MRC
- UCOS系统简介
- 数据结构中的排序
- Android SDK 开发范例大全 ---3.8手机页面的转换
- systemd详解
- iOS_跳转到系统设置
- SDN学习笔记(linux命令)
- JavaScript学习1-JS简介
- Animation
- haproxy web跳转 通过/xx 跳转
- MCU之STM32可用硬件(外部接口)一览表
- lamp建站的笔记