最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android實現(xiàn)圖片雙指縮放

 更新時間:2021年11月03日 15:24:16   作者:Prosper Lee  
這篇文章主要為大家詳細(xì)介紹了Android實現(xiàn)圖片雙指縮放,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了Android實現(xiàn)圖片雙指縮放的具體代碼,供大家參考,具體內(nèi)容如下

展示

源碼

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

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論

长武县| 交城县| 夏河县| 凤台县| 孙吴县| 太仓市| 喜德县| 班玛县| 遂昌县| 濉溪县| 林周县| 乳山市| 河间市| 西林县| 集贤县| 镇远县| 石门县| 巴彦淖尔市| 四子王旗| 若羌县| 永康市| 新乐市| 石阡县| 青阳县| 望谟县| 临泉县| 灌阳县| 韶关市| 紫金县| 大英县| 筠连县| 台中市| 沿河| 于田县| 阿拉尔市| 瓦房店市| 织金县| 海宁市| 沙雅县| 蓝山县| 固阳县|