在线中文-在线在线ccc66-在线永久免费观看的毛片-在线永久免费观看的a站视频-久久精品最新免费国产成人-久久精品综合一区二区三区

以文本方式查看主題

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

--  作者:wangxinxin
--  發(fā)布時間:2010-12-3 11:06:23
--  Android中級教程
大家好,我們這一節(jié)講的是手機頁面的轉(zhuǎn)換setContentView 的應(yīng)用.在網(wǎng)頁的世界里,想要在兩個頁面間的轉(zhuǎn)換,只要利用超鏈接就可以實現(xiàn),
但是在手機的世界里,要如何實現(xiàn)手機頁面的轉(zhuǎn)換呢? 最簡單的方法就是改變Activity 的Layout !
      在這個例子中,將布局兩個Layout ,分別為Layout1(main.xml) 和Layout2(mylayout.xml), 默認(rèn)的Layout 為main.xml, 我們在Layout1 當(dāng)中創(chuàng)建一個按鈕,當(dāng)單擊按鈕時,顯示第二個Layout(mylayout.xml) ;同樣地,在Layout2 里也設(shè)計一個按鈕,當(dāng)單擊第二個Layout 的按鈕之后,剛顯示回原來的Layout1 ,現(xiàn)在就來示范如何在兩個頁面之間互相切換.
首先看一下效果圖(為了區(qū)別兩個Layout ,我們分別設(shè)置了不同的背景色):
    1.jpg 2.jpg
下面是我們本程序所涉及的相關(guā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="歡迎來到魏祝林的博客"
    />
<Button
    android:id="@+id/bt1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="點擊進(jìn)入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="點擊進(jìn)入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();
            }
        });
    }
}
最后執(zhí)行之!,這一節(jié)就到此結(jié)束~
主站蜘蛛池模板: 色激情五月 | 麻豆日韩区久久综合 | 亚洲欧美亚洲 | 亚洲国产成人久久一区久久 | 欧美精品久久 | 国产福利专区精品视频 | 在线毛片网| 在线国产高清 | 日韩男人天堂 | 中文字幕亚洲综合久久2 | 国产一区在线看 | 欧美日韩国产一区 | 久久久久亚洲视频 | 日韩精品免费看 | 亚洲深夜福利视频 | 在线成人综合色一区 | 99爱在线视频这里只有精品 | 六月丁香在线播放 | 六月丁香深爱六月综合激情 | 99热国产这里只有精品99 | 五月婷婷激情六月 | 亚洲电影免费在线看精品国产 | 综合五月天婷婷丁香 | 羞羞视频.www在线观看 | 国内露脸自拍 | 亚洲区精品久久一区二区三区 | 成人欧美一区二区三区视频 | 亚洲精品9999久久久久 | 亚洲国产成人精品女人久久久 | 男人天堂网2019 | 亚洲最大的黄色 | 午夜欧美精品久久久久久久 | 亚洲福利视频网址 | 樱花aⅴ一区二区三区四区 亚洲天堂男人的天堂 | 天堂激情 | 国产在线乱码在线视频 | 一级片在线免费看 | 亚洲五月激情 | 这里只有精品66 | 都市激情男人天堂 | 自拍偷拍网站 |