Android: Creating a “Snapping” Horizontal Scroll View

This type of view is fairly common in the mobile world, but doesn’t come out of the box with the Android SDK. Think of the home screen(s) on an Android device. You can slide between each home screen and when you lift your finger, it “snaps” to the most appropriate screen. This is fairly simple to build yourself using the existing HorizontalScrollView (or regular ScrollView for vertical scrolling) and adding some code on top of it to handle snapping to each screen. In this post, I’ll show you how I implemented this view for a rotating article feature.