Dynamic switching on the android local Interface

Source: Internet
Author: User

Recently, I am working on Tablet development. I think the activity is as good as the web page. The Local interface is fixed, and the Local interface can be dynamically switched. The effect is as follows:

 

This effect consists of three 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>

The following is the Java code

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. setonclick Listener (New onclicklistener () {Boolean boo = false; @ override public void onclick (view v) {boo =! Boo; If (BOO) {getviewone () ;}else {getviewsecond () ;}});/** whether to display 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 );}}

 

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.