欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

android編程實(shí)現(xiàn)局部界面動(dòng)態(tài)切換的方法

 更新時(shí)間:2015年11月11日 15:41:00   作者:jie1991liu  
這篇文章主要介紹了android編程實(shí)現(xiàn)局部界面動(dòng)態(tài)切換的方法,以實(shí)例形式較為詳細(xì)的分析了Android局部切換的布局及功能實(shí)現(xiàn)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下

本文實(shí)例講述了android編程實(shí)現(xiàn)局部界面動(dòng)態(tài)切換的方法。分享給大家供大家參考,具體如下:

局部界面固定,局部界面可以動(dòng)態(tài)切換。效果如下:

這個(gè)效果由3個(gè)layout構(gòu)成

main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:orientation="horizontal" >
  <LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_weight="1"
    android:background="@android:color/black" >
    <Button
      android:id="@+id/btnSwitch"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="switch" />
    <Button
      android:id="@+id/btnScreen"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="screen" />
  </LinearLayout>
  <LinearLayout
    android:id="@+id/frameSwitch"
    android:layout_width="160dp"
    android:layout_height="fill_parent"
    android:background="@android:color/white" >
  </LinearLayout>
</LinearLayout>

one.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:background="@color/yellow"
  android:orientation="vertical" >
  <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="this is linearLayout one" />
</LinearLayout>

two.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:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="this is linearLayout two" />
  <Button
    android:id="@+id/btnSecond"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="btnSecond" />
</LinearLayout>

下面是Java代碼

public class ZzzAndroidActivity extends Activity {
  private LinearLayout frameSwitch;
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    frameSwitch = (LinearLayout) findViewById(R.id.frameSwitch);
    Button btnSwitch = (Button) findViewById(R.id.btnSwitch);
    btnSwitch.setOnClickListener(new OnClickListener() {
      boolean boo = false;
      @Override
      public void onClick(View v) {
        boo = !boo;
        if (boo) {
          getViewOne();
        } else {
          getViewSecond();
        }
      }
    });
    /*
     * 是否全屏
     */
    Button btnScreen = (Button) findViewById(R.id.btnScreen);
    btnScreen.setOnClickListener(new OnClickListener() {
      boolean isScreen = false;
      @Override
      public void onClick(View v) {
        isScreen = !isScreen;
        if (isScreen) {
          frameSwitch.setVisibility(android.view.View.GONE);
        } else {
          frameSwitch.setVisibility(android.view.View.VISIBLE);
        }
      }
    });
  }
  public void getViewOne() {
    View viewOne = getLayoutInflater().inflate(R.layout.one, null);
    frameSwitch.removeAllViews();
    frameSwitch.addView(viewOne, LayoutParams.FILL_PARENT,
        LayoutParams.FILL_PARENT);
  }
  public void getViewSecond() {
    View viewSecond = getLayoutInflater().inflate(R.layout.two, null);
    Button btn = (Button) viewSecond.findViewById(R.id.btnSecond);
    btn.setOnClickListener(new OnClickListener() {
      @Override
      public void onClick(View v) {
        Toast.makeText(ZzzAndroidActivity.this, "hello world",
            Toast.LENGTH_LONG).show();
      }
    });
    frameSwitch.removeAllViews();
    frameSwitch.addView(viewSecond, LayoutParams.FILL_PARENT,
        LayoutParams.FILL_PARENT);
  }
}

希望本文所述對(duì)大家Android程序設(shè)計(jì)有所幫助。

相關(guān)文章

  • Kotlin中Stack與LinkedList的實(shí)現(xiàn)方法示例

    Kotlin中Stack與LinkedList的實(shí)現(xiàn)方法示例

    這篇文章主要給大家介紹了關(guān)于Kotlin中Stack與LinkedList實(shí)現(xiàn)的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考借鑒,下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2018-06-06
  • Android跑馬燈MarqueeView源碼解析

    Android跑馬燈MarqueeView源碼解析

    這篇文章主要為大家詳細(xì)介紹了Android跑馬燈MarqueeView源碼,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-01-01
  • Android在JNI中使用ByteBuffer的方法

    Android在JNI中使用ByteBuffer的方法

    這篇文章主要介紹了Android在JNI中使用ByteBuffer的方法,涉及Android中緩沖區(qū)的相關(guān)使用技巧,需要的朋友可以參考下
    2015-04-04
  • APK包名修改 請(qǐng)問(wèn)如何修改APK包名

    APK包名修改 請(qǐng)問(wèn)如何修改APK包名

    今天,想在android手機(jī)上安裝兩個(gè)相同的應(yīng)用,本以為可以安裝不同版本的,試了幾次,均相互覆蓋了,于是,只能設(shè)法修改apk所對(duì)應(yīng)的包名(package name),需要了解的朋友可以參考下
    2012-12-12
  • Android仿淘寶首頁(yè)頭條View垂直滾動(dòng)效果

    Android仿淘寶首頁(yè)頭條View垂直滾動(dòng)效果

    這篇文章主要為大家詳細(xì)介紹了Android仿淘寶首頁(yè)頭條View垂直滾動(dòng)效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-05-05
  • Android通過(guò)ViewModel保存數(shù)據(jù)實(shí)現(xiàn)多頁(yè)面的數(shù)據(jù)共享功能

    Android通過(guò)ViewModel保存數(shù)據(jù)實(shí)現(xiàn)多頁(yè)面的數(shù)據(jù)共享功能

    這篇文章主要介紹了Android通過(guò)ViewModel保存數(shù)據(jù)實(shí)現(xiàn)多頁(yè)面的數(shù)據(jù)共享功能,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2019-11-11
  • Android PicSelector圖片選擇器小功能

    Android PicSelector圖片選擇器小功能

    這篇文章主要為大家詳細(xì)介紹了Android PicSelector圖片選擇器小功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-08-08
  • Android 自定義狀態(tài)欄實(shí)例代碼

    Android 自定義狀態(tài)欄實(shí)例代碼

    本文通過(guò)實(shí)例代碼給大家講解了Android 自定義狀態(tài)欄知識(shí),非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友參考下
    2017-02-02
  • Android spinner下垃菜單用法實(shí)例詳解

    Android spinner下垃菜單用法實(shí)例詳解

    這篇文章主要介紹了Android spinner下垃菜單用法,詳細(xì)分析了spinner下垃菜單的定義、布局及功能實(shí)現(xiàn)相關(guān)技巧,需要的朋友可以參考下
    2016-07-07
  • Android Native庫(kù)的加載及動(dòng)態(tài)鏈接的過(guò)程

    Android Native庫(kù)的加載及動(dòng)態(tài)鏈接的過(guò)程

    這篇文章主要介紹了Android Native庫(kù)的加載及動(dòng)態(tài)鏈接的加載過(guò)程,需要的朋友可以參考下
    2018-01-01

最新評(píng)論