Trying SlidingPaneLayout With Fragments (In Android)

Trying SlidingPaneLayout with Fragments (in Android)

Building on my last few posts, I wanted to try out the new SlidingPaneLayout that’s being offered in the support library. For the uninitiated, here’s a Google I/O presentation that presents SlidingPaneLayout along with a few other new UI concepts for Android:

This was super simple to do, so I’m going to go fairly quickly again.

Instructions

0

My last few posts, are prerequisites for this one. So, make sure that you’re up to speed on those.

1

Add a SlidingPaneLayout section to your activity, it should contain a couple views that you can attach things to later. Since we’re attaching fragments, these needed to be some sort of ViewGroup, and FrameLayout implements that.

2

In the MainActivity, we want to grab a reference to the SlidingPane, start it as open by default, and attach our content to it. Our content happens to be fragments, but you can attach whatever views you feel like here.

3

The fragments are pretty simple, we simply inflate the layout. I also decided to put some text and a color in there.

4

This is the layout file used by the fragments.

Conclusion

This whole thing took less time than it did to install the 0.2.6 upgrade for Android Studio, so if you’re thinking about using a SlidingPaneLayout, it’s incredibly simple, so just go for it!

Github repo here.