Android編程之頁面切換測試實(shí)例
本文實(shí)例講述了Android編程之頁面切換測試。分享給大家供大家參考。具體分析如下:
一、軟件平臺(tái):
win7 + eclipse + sdk
二、設(shè)計(jì)思路:
兩個(gè)頁面:mian和ok,每個(gè)頁面上有一個(gè)按鍵,點(diǎn)擊則可以互相切換
三、源代碼:
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" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="下一頁面 "></Button> </LinearLayout>
ok.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"> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="上一頁面 " android:id="@+id/button1"></Button> </LinearLayout>
makechoice源代碼:
package com.makechoice; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.widget.Button; public class makechoice extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Button btn = (Button)findViewById(R.id.button1); btn.setOnClickListener(new Button.OnClickListener() { @Override public void onClick(View v) { jump2ok(); } }); } //跳到ok頁面 public void jump2ok() { setContentView(R.layout.ok); //當(dāng)有按鍵按下跳到main頁面 Button btn = (Button)findViewById(R.id.button1); btn.setOnClickListener(new Button.OnClickListener() { @Override public void onClick(View v) { jump2main(); } }); } //跳到main頁面 public void jump2main() { setContentView(R.layout.main); //當(dāng)有按鍵按下跳到ok頁面 Button btn = (Button)findViewById(R.id.button1); btn.setOnClickListener(new Button.OnClickListener() { @Override public void onClick(View v) { jump2ok(); } }); } }
四、運(yùn)行效果圖:
五、注意:
類R中存放的ID號(hào)為當(dāng)前頁面的ID號(hào),所以findViewById函數(shù)捕獲的控件也為當(dāng)前頁面的控件
希望本文所述對(duì)大家的Android程序設(shè)計(jì)有所幫助。
- Android實(shí)現(xiàn)移動(dòng)小球和CircularReveal頁面切換動(dòng)畫實(shí)例代碼
- Android 實(shí)現(xiàn)無網(wǎng)絡(luò)頁面切換的示例代碼
- Android中TabLayout結(jié)合ViewPager實(shí)現(xiàn)頁面切換
- Android 中使用 ViewPager實(shí)現(xiàn)屏幕頁面切換和頁面輪播效果
- Android開發(fā)中ViewPager實(shí)現(xiàn)多頁面切換效果
- Android中TabLayout結(jié)合ViewPager實(shí)現(xiàn)頁面切換效果
- Android中使用TabHost 與 Fragment 制作頁面切換效果
- Android使用Fragment打造萬能頁面切換框架
- Android fragment實(shí)現(xiàn)多個(gè)頁面切換效果
相關(guān)文章
Android顯式啟動(dòng)與隱式啟動(dòng)Activity的區(qū)別介紹
為什么要寫顯式啟動(dòng)與隱式啟動(dòng)Activity,Android的Acitivity啟動(dòng)大致有兩種方式:顯式啟動(dòng)與隱式啟動(dòng),下面分別介紹2014-09-09Android實(shí)現(xiàn)拍照截取和相冊(cè)圖片截取
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)拍照截取和相冊(cè)獲取圖片截取,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-12-12Flutter listview如何實(shí)現(xiàn)下拉刷新上拉加載更多功能
這篇文章主要給大家介紹了關(guān)于Flutter listview如何實(shí)現(xiàn)下拉刷新上拉加載更多功能的相關(guān)資料,對(duì)于新聞列表數(shù)據(jù)的更新和加載更多是必不可少的,而實(shí)現(xiàn)下拉刷新與上劃加載更多的方式有很多種,需要的朋友可以參考下2021-08-08Android自定義View實(shí)現(xiàn)隨手勢滑動(dòng)控件
這篇文章主要為大家詳細(xì)介紹了Android自定義View實(shí)現(xiàn)隨手勢滑動(dòng)的控件,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-02-02Android編程實(shí)現(xiàn)自定義漸變顏色效果詳解
這篇文章主要介紹了Android編程實(shí)現(xiàn)自定義漸變顏色效果,結(jié)合具體實(shí)例形式分析了Android基于xml及代碼定義來實(shí)現(xiàn)顏色漸變的相關(guān)操作技巧與注意事項(xiàng),需要的朋友可以參考下2017-08-08Android漲姿勢知識(shí)點(diǎn)之你沒用過的BadgeDrawable
現(xiàn)在Android中有許多的應(yīng)用仿蘋果的在應(yīng)用圖標(biāo)上顯示小紅點(diǎn),下面這篇文章主要給大家介紹了關(guān)于Android漲姿勢知識(shí)點(diǎn)之你沒用過的BadgeDrawable的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-09-09Android動(dòng)態(tài)添加設(shè)置布局與控件的方法
這篇文章主要介紹了Android動(dòng)態(tài)添加設(shè)置布局與控件的方法,涉及Android中布局與控件的相關(guān)操作技巧,需要的朋友可以參考下2016-01-01