午夜伦理在线-午夜伦理在线观看-午夜毛片免费看-午夜美女久久久久爽久久-午夜免费

以文本方式查看主題

-  曙海教育集團論壇  (http://www.brpp.cn/bbs/index.asp)
--  Android應用開發  (http://www.brpp.cn/bbs/list.asp?boardid=45)
----  Android中級教程  (http://www.brpp.cn/bbs/dispbbs.asp?boardid=45&id=2020)

--  作者:wangxinxin
--  發布時間:2010-12-3 11:06:23
--  Android中級教程
大家好,我們這一節講的是手機頁面的轉換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();
            }
        });
    }
}
最后執行之!,這一節就到此結束~
主站蜘蛛池模板: 久久久男女野外野战 | 青青青国产依人精品视频 | 性激烈的欧美暴力三级视频 | 国产美女高清片免费观看 | 最新亚洲精品国自产在线观看 | 久久亚洲精品中文字幕亚瑟 | 久久久久女人精品毛片 | 丁香五六月婷婷 | 亚洲黄v| 黄网在线免费 | 91精东| 野草在线观看视频精品 | 亚洲精品成人网 | 中文字幕第一页亚洲 | 久久精品在线观看 | 97色片| 免费的全黄一级录像带 | 亚洲欧美日韩激情在线观看 | 成年大片免费高清在线观看 | 毛片在线免费播放 | 天天影视综合网色综合国产 | 精品国产三级a∨在线观看 精品国产三级在线观看 | 米奇精品一区二区三区 | 亚洲第一黄| 高清毛片一区二区三区 | 日韩美女专区中文字幕 | 成人影院午夜久久影院 | 国产黄频在线观看高清免费 | 成在线人免费视频 | sese久久| 亚洲综合精品香蕉久久网97 | 精品免费久久久久久成人影院 | 伊人色综合久久天天爱 | 国产一区二区视频在线播放 | 精品湿 | 国产成人精品视频免费 | 成人免费视频一区 | 国产成人精品一区二区免费视频 | 久久精品国产精品亚洲红杏 | 欧美日韩在线精品一区二区三区 | 黄色网址在线播放 |