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

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

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

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

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

這個效果由3個layout構成

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);
  }
}

希望本文所述對大家Android程序設計有所幫助。

相關文章

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

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

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

    Android跑馬燈MarqueeView源碼解析

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

    Android在JNI中使用ByteBuffer的方法

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

    APK包名修改 請問如何修改APK包名

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

    Android仿淘寶首頁頭條View垂直滾動效果

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

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

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

    Android PicSelector圖片選擇器小功能

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

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

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

    Android spinner下垃菜單用法實例詳解

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

    Android Native庫的加載及動態(tài)鏈接的過程

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

最新評論