The method of implementing local interface dynamic handoff by Android programming _android

Source: Internet
Author: User

This paper illustrates the method of implementing the local interface dynamic handoff by Android programming. Share to everyone for your reference, specific as follows:

The local interface is fixed and the local interface can be dynamically switched. The effect is as follows:

This effect is composed of 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" &
  Gt <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:layo
      Ut_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" and roid:text= "screen"/> </LinearLayout> <linearlayout android:id= "@+id/frameswitch" Android:layout_w Idth= "160DP" android:layout_height= "fill_parent" android:background= "@android: Color/white" > </linearlayou

T> </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:o" rientation= "vertical" >
  <textview
    android:layout_width= "Wrap_content"
    Wrap_content '
    android:text= ' is linearlayout two '/> <button
  android:id=
    ' @+id/btnsecond '
    android:layout_width= "wrap_content"
    android:layout_height= "wrap_content"
    android:text= " Btnsecond "/>
</LinearLayout>

Here is the Java code

public class Zzzandroidactivity extends activity {private LinearLayout frameswitch; /** called the activity is a.
    * * @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 ();
    }
      }
    });
    * * Whether full screen/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);

 }
}

I hope this article will help you with your Android programming.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.