Custom renderer for ScrollView on Android.

Neil-PepperNeil-Pepper GBUniversity ✭✭

Want to add simple paging to scrollview. On iOS is was easy added customer renderer like this

[assembly:ExportRenderer (typeof(ScrollView), typeof(JustEat.Ordertracker.Touch.Renderers.ExtendedScrollViewRenderer))]
namespace JustEat.Ordertracker.Touch.Renderers
{
public class ExtendedScrollViewRenderer : ScrollViewRenderer
{
protected override void OnElementChanged (VisualElementChangedEventArgs e)
{
base.OnElementChanged (e);
UIScrollView iosScrollView = (UIScrollView)NativeView;
iosScrollView.PagingEnabled = true;
iosScrollView.ShowsHorizontalScrollIndicator = false;
}
}
}

So doesn't like like android has paging flag so was going to implement wih touch events or similar, but can get any events to trigger. SO have tried hooking up events and overtiding

[assembly:ExportRenderer (typeof(ScrollView), typeof(JustEat.Ordertracker.Touch.Renderers.ExtendedScrollViewRenderer))]
namespace JustEat.Ordertracker.Touch.Renderers
{
public class ExtendedScrollViewRenderer : ScrollViewRenderer
{
protected override void OnElementChanged (VisualElementChangedEventArgs e)
{
base.OnElementChanged (e);
global::Android.Widget.ScrollView droidScrollView = (global::Android.Widget.ScrollView)this;

        droidScrollView.HorizontalScrollBarEnabled = false;

        droidScrollView.Drag += delegate
        {
            Console.WriteLine("Drag");
        };
    }

    public override bool OnTouchEvent(global::Android.Views.MotionEvent ev)
    {
        Console.WriteLine("OnTouchEvent");
        return base.OnTouchEvent(ev);
    }
}

}

The OnElementChanged definitely gets called as i hit a breakpoint, but the events do nothing, neither does setting HorizontalScrollBarEnabled to false, or even setting .Enabled to false. Its like I have access to a differnt object ?

any ideas ?

thanks

Best Answer

  • Neil-PepperNeil-Pepper GBUniversity ✭✭
    Accepted Answer

    Think ended up using Xamarin.forms.Carousel did what i needed.

Answers

  • AlexRutherfordAlexRutherford GBUniversity ✭✭

    Hey, what was your solution for this problem? I am also trying to do the same.

  • Neil-PepperNeil-Pepper GBUniversity ✭✭
    Accepted Answer

    Think ended up using Xamarin.forms.Carousel did what i needed.

Sign In or Register to comment.