Android Swipe View with Tabs Without Using the V4 support library

喜夏-厌秋 提交于 2019-12-03 09:35:51
garlix

I know this is a very old question but I think it's still relevant. I was searching for a workaround: using viewpager without having to convert all my entire projects to the v4 support library.

The answer is the v13 support library!. In this way you can have a viewpager on the activity but then use android.support.v13.app.FragmentStatePagerAdapter to maintain compability with fragments and other useful stuff.

Hope it helps some google-addicted-searcher.

As mentioned by @Luksprog you can copy ViewPager code in your own project and replace support library references by native one. Most likely you will need to do the same with FragmentPagerAdapter, FragmentStatePagerAdapter and PagerAdapter. I grab the code from grepcode.com.

It took me 2 hours to do the trick, even though I was a beginner with android. But it mean more line of code to maintain and in the end I switched back to support library.

Now I'm no Android SDK guru, but I would just use the Support Library. Here's an excerpt from the RenderScript documentation,

"We strongly recommend using the Support Library APIs for accessing RenderScript because they include the latest improvements to the RenderScript compute framework and provide a wider range of device compatibility."

Now this is for the v8 Support Library, but I'm guessing that this recommendation can be extrapolated. It makes sense that the latest improvements will be in Android's support libraries because they can be updated independently from platform updates.

Just be sure to enable ProGuard before releasing so you can trim the excess fat of the unused parts of the API.

Also you can use the ViewFLipper class but you have to manual implement the Animations and the GestureDetector, you can find some code here

You should use support library package because it provide backward-compatible versions of Android Framework APIs. Use what they recommended is the best way to deal with android from my experience.

or read this

http://www.velir.com/blog/index.php/2010/11/17/android-snapping-horizontal-scroll/

Using the support library is encouraged in general since it contains the latest piece of code of every API. What B.Young is pointing on RenderScript applies to all the other APIs.

-------- No need to keep reading.

Let's put an example. Let say that when Android 8 is released they introduce a new class to hold values referenced to keys called FastMap. To add support for older versions, Google releases a support library with this new class, and two months later during performance tests they find a way to make it more efficient, so they release an update of that support library with the optimized version of FastMap (since Android OS is frozen into the phone).

Additionally, and since big number releases are always a bit rushed, Google realizes that they introduced a very specific bug (yehh, it happens), which gets fixed on a newer update.

So if were to build an Android app for Android 8 and above and used the built-in APIs, you'd be missing all these improvements coming in the support code.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!