Search code examples
androidanimationxamarinparallax

How can I achieve an infinite scrolling animation effect in Xamarin Android?


I'm making an app in Xamarin Android and I want to achieve something like this: https://github.com/Q42/AndroidScrollingImageView

Basically, it's an infinite scrolling image animation. I'm really new to android development let alone Xamarin so I'm at a loss here. I dont think the Translate animation in XML would work here. I'm thinking of translating 2 ImageViews but I dont know how to do that outside XML.

Is there a library similar to that one for Xamarin? Thanks in advance!


Solution

  • The cool thing about Xamarin.Android is that you can easily reuse existing Java libraries. If you are fine with using the AndroidScrollingImageView library instead of rolling out your own implemenetation, here's what you should do:

    1. Clone or download the project to your own computer and build the library.
    2. As a result, you'll get a JAR file that contains the AndroidScrollingImageView control.
    3. Create a new binding project and import the JAR file.
    4. Xamarin.Android wraps the library with C# wrappers so you can invoke Java code from C#.
    5. Now you can use the control in your AXML layouts and call the methods in code.

    It's worth reading the binding article to understand how this works. There's also a good binding library example here, where James Montemagno does exactly what you want to do. You might want to study it to see how the binding works in real life.