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