<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TextView android:text="Layout 1" android:textAppearance="?android:attr/textAppearanceLarge" android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/textView1" android:gravity="center" /> <Button android:text="Go to Layout 2" android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/btn1" /> </LinearLayout>
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:minWidth="25px" android:minHeight="25px"> <TextView android:text="Layout 2" android:textAppearance="?android:attr/textAppearanceLarge" android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/textView2" android:gravity="center" /> <Button android:text="Go to Layout 3" android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/btn2" /> </LinearLayout>
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:minWidth="25px" android:minHeight="25px"> <TextView android:text="Layout 3" android:textAppearance="?android:attr/textAppearanceLarge" android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/textView3" android:gravity="center" /> <Button android:text="Go to Layout 1" android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/btn3" /> </LinearLayout>
using System; using Android.App; using Android.Content; using Android.Runtime; using Android.Views; using Android.Widget; using Android.OS; namespace myFirstApps { [Activity(Label = "myFirstApps", MainLauncher = true, Icon = "@drawable/icon")] public class MainActivity : Activity { protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // Set our view from the "main" layout resource ShowLayout1(); } // Layout 1 (Main.axml) private void ShowLayout1() { SetContentView(Resource.Layout.Main); Button btn1 = FindViewById<Button>(Resource.Id.btn1); btn1.Click += delegate { ShowLayout2(); }; } // Layout 2 (Main2.axml) private void ShowLayout2() { SetContentView(Resource.Layout.Main2); Button btn2 = FindViewById<Button>(Resource.Id.btn2); btn2.Click += delegate { ShowLayout3(); }; } // Layout 3 (Main3.axml) private void ShowLayout3() { SetContentView(Resource.Layout.Main3); Button btn3 = FindViewById<Button>(Resource.Id.btn3); btn3.Click += delegate { ShowLayout1(); }; } } }
ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท