Skip to content

Instantly share code, notes, and snippets.

@conceptdev
Created February 28, 2011 23:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save conceptdev/848289 to your computer and use it in GitHub Desktop.
Save conceptdev/848289 to your computer and use it in GitHub Desktop.
Custom Android Gallery in MonoDroid: one-view-at-a-time scrolling
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.Util;
/*
Source:
http://stackoverflow.com/questions/4582123/creating-a-custom-gallery-overriding-onfling
Usage:
<net.conceptdevelopment.monodroid.mygallery android:id="@+id/examplegallery"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
*/
namespace net.conceptdevelopment.monodroid
{
public class mygallery: Gallery, IJavaObject
{
public mygallery(Context ctx)
: base(ctx)
{ }
public mygallery(IntPtr handle)
: base(handle)
{ }
public mygallery(Context ctx, IAttributeSet attrs)
: base(ctx, attrs)
{ }
private bool isScrollingLeft(MotionEvent e1, MotionEvent e2)
{
return e2.GetX() > e1.GetX();
}
public override bool OnFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY)
{
//int kEvent;
Android.Views.Keycode kCode;
if (isScrollingLeft(e1, e2))
{ //Check if scrolling left
kCode = Android.Views.Keycode.DpadLeft;
}
else
{ //Otherwise scrolling right
kCode = Android.Views.Keycode.DpadRight;
}
OnKeyDown(kCode, null);
return true;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment