展示

源码
using Android.App;
using Android.OS;
using Android.Util;
using Android.Views;
using Android.Widget;
namespace android_by_csharp
{
[Activity(Label = "@string/app_name", Theme = "@style/AppTheme", MainLauncher = true)]
public class MainActivity : Activity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.main);
var avatar = FindViewById<ImageView>(Resource.Id.avatar);
var distance = 0;
if (avatar != null)
avatar.Touch += (sender, args) =>
{
if (args.Event == null) return;
if ((args.Event.Action & MotionEventActions.Pointer2Down) == MotionEventActions.Pointer2Down)
distance = (int)Distance(args.Event);
else if ((args.Event.Action & MotionEventActions.Pointer2Up) == MotionEventActions.Pointer2Up)
Toast.MakeText(this, "双指抬起", ToastLength.Short)?.Show();
if ((args.Event.Action & MotionEventActions.Move) == 0 || args.Event.PointerCount != 2) return;
var moveDistance = Distance(args.Event);
avatar.ScaleY = avatar.ScaleX *= moveDistance / distance;
if (moveDistance / distance < 1)
Toast.MakeText(this, "缩小", ToastLength.Short)?.Show();
else if (moveDistance / distance > 1)
Toast.MakeText(this, "放大", ToastLength.Short)?.Show();
};
}
private static float Distance(MotionEvent motionEvent)
{
var x = motionEvent.GetX(0) - motionEvent.GetX(1);
var y = motionEvent.GetY(0) - motionEvent.GetY(1);
return FloatMath.Sqrt(x * x + y * y);
}
}
}