3.8 MonoForAndroid用户人机界面-手机页面的转换

手机页面之间的转换最简单的方式就是改变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(); };
        }
    }
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值