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

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

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

本文實(shí)例為大家分享了Android實(shí)現(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();

                    // 移動(dòng),雙指
                    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();
                };
        }

        // 計(jì)算兩個(gè)觸摸點(diǎn)之間的距離
        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);
        }
    }
}

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

相關(guān)文章

最新評(píng)論

图片| 莱西市| 胶南市| 绩溪县| 香格里拉县| 名山县| 闸北区| 崇阳县| 得荣县| 红原县| 西宁市| 泗洪县| 崇义县| 扶沟县| 河池市| 古丈县| 全南县| 横峰县| 鹰潭市| 唐山市| 黄山市| 木兰县| 台东市| 错那县| 华宁县| 隆子县| 郯城县| 根河市| 贵南县| 田阳县| 瓦房店市| 德令哈市| 祁连县| 张北县| 遵义市| 科技| 榕江县| 朔州市| 随州市| 西畴县| 荥阳市|