亚洲成人伦理_成人午夜视频在线观看_日本免费网站_黄网站色大毛片_超碰97人人人人人蜜桃_久久在线视频

Rss & SiteMap

曙海教育集團論壇 http://www.bjzhda.cn

曙海教育集團論壇
共1 條記錄, 每頁顯示 10 條, 頁簽: [1]
[瀏覽完整版]

標題:Android中級教程

1樓
wangxinxin 發表于:2010-12-3 11:06:23
大家好,我們這一節講的是手機頁面的轉換setContentView 的應用.在網頁的世界里,想要在兩個頁面間的轉換,只要利用超鏈接就可以實現,
但是在手機的世界里,要如何實現手機頁面的轉換呢? 最簡單的方法就是改變Activity 的Layout !
      在這個例子中,將布局兩個Layout ,分別為Layout1(main.xml) 和Layout2(mylayout.xml), 默認的Layout 為main.xml, 我們在Layout1 當中創建一個按鈕,當單擊按鈕時,顯示第二個Layout(mylayout.xml) ;同樣地,在Layout2 里也設計一個按鈕,當單擊第二個Layout 的按鈕之后,剛顯示回原來的Layout1 ,現在就來示范如何在兩個頁面之間互相切換.
首先看一下效果圖(為了區別兩個Layout ,我們分別設置了不同的背景色):
    1.jpg 2.jpg
下面是我們本程序所涉及的相關代碼,首先是主界面布局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="歡迎來到魏祝林的博客"
    />
<Button
    android:id="@+id/bt1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="點擊進入Layout2"
/>
</LinearLayout>
其次我們在main.xml 同一目錄新建一個為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="#ffffffff"
    >
<TextView  
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="Welcome to Mr Wei's blog"
    />
<Button
    android:id="@+id/bt2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="點擊進入Layout1"
/>
</LinearLayout>
最后是我們的核心程序setContentViewDemo.java
package com.android.setContentViewDemo;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class setContentViewDemo extends Activity {
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // 載入main.xml Layout
        setContentView(R.layout.main);
        // 以findViewById()取得Button對象并添加事件onClickLisener
        Button bt1 = (Button) findViewById(R.id.bt1);
        bt1.setOnClickListener(new Button.OnClickListener() {
            public void onClick(View v) {
                goToLayout2();
            }
        });
    }
    // 將layout由main.xml切換成mylayout.xml
    public void goToLayout2() {
        // 將layout改成mylayout
        setContentView(R.layout.mylayout);
        Button b2 = (Button) findViewById(R.id.bt2);
        b2.setOnClickListener(new Button.OnClickListener() {
            public void onClick(View v) {
                goToLayout1();
            }
        });
    }
    // 將layout由mylayout.xml切換成main.xml
    public void goToLayout1() {
        setContentView(R.layout.main);
        Button bt1 = (Button) findViewById(R.id.bt1);
        bt1.setOnClickListener(new Button.OnClickListener() {
            public void onClick(View v) {
                goToLayout2();
            }
        });
    }
}
最后執行之!,這一節就到此結束~
共1 條記錄, 每頁顯示 10 條, 頁簽: [1]

Copyright © 2000 - 2009 曙海教育集團
Powered By 曙海教育集團 Version 2.2
Processed in .03125 s, 2 queries.
主站蜘蛛池模板: 九九热热九九 | 欧美高清hd | 国产一区二区三区视频 | 国产精品久久久久久吹潮 | 久久成人av| 伊人爽| 欧美黑人国产人伦爽爽爽 | 国产精品网址 | 日韩成人高清在线 | 9191av| 久久伊人亚洲 | 欧美伊人久久久久久久久影院 | 欧美簧片 | 午夜在线视频 | caoporn国产精品免费公开 | 欧美四虎 | 欧美人妖网站 | 欧美精品国产一区二区 | 国产一区二区在线播放 | 亚洲天堂网站 | 亚洲中午字幕 | 男女深夜网站 | 91大神在线资源观看无广告 | 国产乱人伦 | 嫩草一区二区三区 | 日韩欧美电影在线 | 亚洲国产精品激情在线观看 | 日本公妇乱淫xxxⅹ 国产在线不卡 | 欧美一二三四成人免费视频 | 中文字幕在线不卡播放 | 欧美精品一区二区三区在线播放 | 欧美一区二区成人 | 国产高清久久久 | 天天操夜夜操 | 欧美激情va永久在线播放 | 91网站在线观看视频 | 精品一二三区视频 | 在线看91| 欧美综合久久 | 女人av| 在线三级网址 |