Gravity View-A Sensor Based Library for Android

Fahim Sakri
AndroidPub
Published in
2 min readApr 19, 2017

Gravity View is an Android adaptation of Facebook instant articles. The concept behind the library is to utilize the motion sensors of an Android device and allow the end user to explore the product by rotating his device. It uses gyroscope motion sensor readings to scroll the image.

Gravity View Android Library is open sourced on Github. Checkout this link https://github.com/gofynd/gravity-view

Problem:

We were looking for a library that could scroll the image toward side where you tilt the device, this idea is similar to the Fb’s instant article tilt. But we couldn’t find any android native library available which we can easily use it in the app.

Approach

Gravity View is born to be able to make motion sensor easy to scroll image in android as simple as it can get. Not everyone needs to look up x, y, z values of Gyroscope Sensor.

In this Library, I have made use of rate of rotation of x, y, z axis of Gyroscope Sensor. Adding extra filter values to make the scroll smooth with a device tilt. Checkout the video shared on how it works.

I recently released the version 1.0 of Gravity View . Let’s walk through the process of integrating Gravity View

It is super simple to integrate Gravity View in your current android project. Simply add the below to your build.gradle dependencies.

compile 'co.gofynd.library:gravity-view:1.0'

..sync your gradle and then add this changes in your xml layout file

and then initialize Gravity View in your activity/fragment and then register and unregister it in your 0nResume and OnStop methods.

Check if device is supported (Optional)

boolean is_supported = gravityView.deviceSupported();

That’s it! Gravity View is integrated into your app.

That said, the android library isn’t perfect and I would love it if you can try it out and file issues on Github to make it better.

Check out Gravity View on Github (Star the repo if you find it useful)

If you have suggestions, please let me know in the comment section.

Till then keep crushing code 🤓

Other articles

P.S. Thanks for reading this far! If you found value in this, I’d really appreciate it if you recommend this post (by clicking the ❤ button) so other people can see it!.

--

--