手机页面之间的转换最简单的方式就是改变Activity的Layout
Main.axml
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/black">
<TextView
android:id="@+id/text1"
android:textSize="24sp"
android:layout_width="186px"
android:layout_height="29px"
android:layout_x="70px"
android:layout_y="32px"
android:text="@string/layout1" />
<Button
android:id="@+id/button1"
android:layout_width="118px"
android:layout_height="wrap_content"
android:layout_x="100px"
android:layout_y="82px"
android:text="Go to Layout2" />
</AbsoluteLayout>
mylayout.axml
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/white">
<TextView
android:id="@+id/text2"
android:textSize="24sp"
android:layout_width="186px"
android:layout_height="29px"
android:layout_x="70px"
android:layout_y="32px"
android:textColor="@drawable/black"
android:text="@string/layout2" />
<Button
android:id="@+id/button2"
android:layout_width="118px"
android:layout_height="wrap_content"
android:layout_x="100px"
android:layout_y="82px"
android:text="Go to Layout1" />
</AbsoluteLayout>
MainActivity.cs
using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
namespace Ex03_08
{
[Activity(Label = "Ex03_08", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : Activity
{
int count = 1;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
// Get our button from the layout resource,
// and attach an event to it
Button button = FindViewById<Button>(Resource.Id.button1);
button.Click += delegate { jumpToLayout2(); };
}
public void jumpToLayout2()
{
/* 将layout改成mylayout.xml */
SetContentView(Resource.Layout.mylayout);
/* 以findViewById()取得Button对象,并加入onClickListener */
Button b2 = (Button)FindViewById(Resource.Id.button2);
b2.Click += delegate { jumpToLayout1(); };
}
/* method jumpToLayout1:将layout由mylayout.xml切换成main.xml */
public void jumpToLayout1()
{
/* 将layout改成main.xml */
SetContentView(Resource.Layout.Main);
/* 以findViewById()取得Button对象,并加入onClickListener */
Button b1 = (Button)FindViewById(Resource.Id.button1);
b1.Click += delegate { jumpToLayout2(); };
}
}
}