Visual Studio 2015 Xamarin.Android - restricts access to the image gallery to only one item for each

When I scroll through the gallery, several images go from right to left, depending on the speed of the swipe. Could you tell me how to limit napkins to just one image at a time, no matter how fast I spent?

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

    }
+4
source share
1 answer

Try overriding the Gallery method OnFling()and not call the superclass method OnFling().

Thus, swipe the gallery on the screen to advance one item in time. This will force the gallery to promote one item per napkin.

: 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.

+2

Source: https://habr.com/ru/post/1655480/


All Articles