Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I implement horizontal swipe not using the support library?

If I do not need to grant support for older versions of android and can just use API 17, is there an alternative way to implement the much advertised horizontal swipe (like in gmail) and not use viewpager, fragmentsactivities (new APIs already have fragments...) etc. to get rid of the support library?

All the tutorials I've found for horizontal swipe show how to do it using the support library and FragmentActivities. Otherwise what is the advantage of the new APIs if I cannot use their native classes and methods?

like image 853
Danny Avatar asked Feb 16 '13 12:02

Danny


2 Answers

to get rid of the support library

ViewPager only exists in the Android Support Library. The Android Support Library is not just for backports.

new APIs already have fragments

ViewPager can use native API Level 11 fragments, though you may need to create your own PagerAdapter. Or, you can use ViewPager without any fragments, using just ordinary View or ViewGroup objects for the pages.

is there an alternative way to implement the much advertised horizontal swipe

You are welcome to write your own replacement for ViewPager. Most developers prefer to reuse ViewPager, for reduced development and maintenance costs.

There is also HorizontalScrollView, an open source HorizontalListView floating around, and so on.

like image 83
CommonsWare Avatar answered Sep 27 '22 20:09

CommonsWare


You can write your own FragmentPagerAdapter which works with android.app.Fragment instead of android.support.v4.app.Fragment to minimize dependency on the support library. You only need to create your own class for the adapter (based on FragmentPagerAdapter from support library which source can be found in folder <android-sdks>/extras/android/support/v4/src/java/android/support/v4/app/). Only modification is in the import section - you should reference Fragment, FragmentManager and FragmentTransaction from android.app instead of android.support.v4.app.

like image 42
Matěj Hrazdíra Avatar answered Sep 27 '22 18:09

Matěj Hrazdíra