Wednesday, April 2, 2014

SlidingUpPanel port for Xamarin Android!

I spent some of my time yesterday on a bit of porting Java to C#, instead of sitting in the sun and drinking beer. I found this pretty neat little library, AndroidSlidingUpPanel, which adds a panel to your app, which slides up from either the bottom or top of your screen. The code itself is very inspired by the innards of SlidingPaneLayout from Support v4.

Anyways, here is a GIF of what it looks like:


Adding to your project is pretty simple. Simply grab it from the Xamarin Component store or if you prefer, you can clone or download it from GitHub, which also has the component, but also the source code. There is a nice sample which will show you how to use this library, but if you just want to get started quickly. Simply add the following code to the AXML layout file you want this panel in:



So the SlidingUpPanelLayout should be the root of your layout, and then it will have two children. First child is your content layout, what your originally had in your layout. The second child is the contents of the panel. Now you are good to go! For more info look at the docs on either the component store or on GitHub!

4 comments:

  1. Hi, aside from the fact that you can, what is the benefit of porting Java code to C# versus just creating a binding? I thought that was one of the main selling points of Xamarin.

    For example, I needed a ListView that had section headers that pinned to the top of the list while scrolling, similar to iOS UITableView sections.

    I found the following Android library on GitHub https://github.com/beworker/pinned-section-listview

    It wasn't a lot of code, and I'm sure I could probably port it over a couple of days, but it was much simpler to just creating a Binding project and use it from my Android project. The other benefit is that I'm able to incorporate updates from the original Android library without having to "port" those changes as well.

    Anyway, just curious on your thoughts.

    Kiliman

    ReplyDelete
  2. Simply the fact that I can tweak the C# code and get rid of the nasty Java listeners makes it compelling enough for me to make a port. Also that the resulting code becomes a lot more clean, because I am in charge.

    ReplyDelete
  3. Ok, that makes sense if you plan on enhancing it in the future. For trivial controls, that's probably feasible. But anything significant would probably be best as a binding. Anyway, thanks for your thoughts.

    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete