Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using ViewPager with native Fragments

Can't seem to find a solution to this problem. I'm creating an Android app which uses Fragments. So far I've been using the native ones as opposed to the support library ones because I'm aiming the app at the Nexus 7. However I've no problem using the support library if it makes no difference to development (I read something about no ActionBar?).

My problem is that I want to have a fragment that fills half the screen and shows a swipeable tabs type area. I want the user to be able to swipe left and right and be shown different Fragments for each "page" (Nested Fragments I know but I read that they're supported now). Basically I want it to be like the Play Store when you're swiping between Top Paid, Top Free etc. except only take up half the screen (which I achieve using a Fragment), the other half of the screen is another Fragment I have already written. Another thing is that within each "page" (such as Top Free etc.) I want to have 2 ListViews.

Crude drawing of what I'm trying to achieve

However it seems that the ViewPager component is only part of the support libraries which I think means I have to change all of my fragments to the support ones. Is this the only way to achieve this layout? There must be an easier way; I've seen something called the Workspace on a Google I/O video before so I assumed it's a very common UI design pattern.

Thanks

like image 295
carlmango11 Avatar asked Jan 08 '13 02:01

carlmango11


1 Answers

You can use ViewPager with native fragments, there are adapters for it in the android.support.v13.app package. You need the v13 support jar to be able to use them.

But there might be advantages with using support fragments anyway: Fragment or Support Fragment?

like image 53
brillenheini Avatar answered Oct 06 '22 20:10

brillenheini