c# – Visual Studio 2015 Xamarin.Android – 将图像库中的数据限制为每个项目只有一个项目

当我滑动图库时,根据滑动速度,多个图像从右向左移动.您可以告诉我如何将滑动限制为一次只有1张图片,无论我刷多快?

[Activity(Label = "App3", MainLauncher = true, Icon = "@drawable/icon")]
    public class MainActivity : Activity
    {
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);


            // Set our view from the "main" layout resource
             SetContentView (Resource.Layout.Main);

            Gallery gallery = (Gallery)FindViewById<Gallery>(Resource.Id.gallery);

            gallery.Adapter = new ImageAdapter(this);

            gallery.ItemClick += delegate (object sender, Android.Widget.AdapterView.ItemClickEventArgs args) {
                Toast.MakeText(this, args.Position.ToString(), ToastLength.Short).Show();
            };
        }

    }

最佳答案 尝试覆盖Gallery OnFling()方法,不要调用超类OnFling()方法.

通过这种方式滑动画廊推进一个项目到时间.
这将使画廊每次滑动前进一个项目.

编辑:
您可以创建一个ExtendedGallery类:

public class ExtendedGallery : Gallery
    {
        public ExtendedGallery(Context context) : base(context)
        {

        }

        public override bool OnFling (MotionEvent e1, MotionEvent e2, float velocityX, float velocityY)
        {
            //return base.OnFling (e1, e2, velocityX, velocityY);
            return false;
        }
    }

然后使用ExtendedGallery而不是Gallery.

点赞