0

I have created a SherlockFragmentActivity that has three fragments for ViewPager. But now I want to use this Activity in NavigationDrawer but I am confused how to do this. Google+ app has this kind of implementation but I am wondering about how to achieve this.

NavigationDrawer will have following UI elements:

  1. FragmentActivity(contains three fragment as ViewPager)
  2. Second Fragment
  3. Third Fragment

Is this kind of layout possible with Navigation Drawer If yes, how should I do it. If not, what should I do to achieve this kind of navigation in my app.

Amar
  • 13,202
  • 7
  • 53
  • 71
user1288005
  • 890
  • 2
  • 16
  • 36

2 Answers2

5

It is very much possible. You just have to create the right layout file for it.

<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <!-- The main content view -->
    <RelativeLayout
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <!-- viewpager goes here -->
    </RelativeLayout>

    <!-- The navigation drawer -->
    <LinearLayout android:id="@+id/left_drawer"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:layout_gravity="start">
        <!-- fragment one goes here in drawer -->
        <!--- fragment two goes here in drawer-->
    </LinearLayout>
</android.support.v4.widget.DrawerLayout>

A DrawerLayout has to have 2 childs, the first is the main content, in your case this will contain the ViewPager and perhaps other stuff. The second child is the Drawer itself.

Use this as the content of your activity. The rest of the information can be found by using the example on the android developers page here

dumazy
  • 13,857
  • 12
  • 66
  • 113
  • Hi dumazy You didn't get my point, may be my question was little confusing. I want NavigationDrawer to have LisView Only and on tap of one of its item it should show ViewPager(with three fragments). I tried to achieve this but now am stuck at another issue and has been scratching my head for last two days.....Its shows all ViewPager's fragment good for first time but doesn't show fragment second time when I return back. I am adding an zipped dropbox link [here](https://www.dropbox.com/s/qa528o2a8lxdkcz/NavDrawer.zip). Please have a look on it. – user1288005 Sep 09 '13 at 08:47
2

You can use below libraries to get navigation model similar to your requirement

  • ActionBarSherlock (github)
  • nested-fragments (github)
  • PagerSlidingTabStrip (github)
  • NavigationDrawer (Android developer site)
  • Latest Support v4 library

Have a look at my post

Below is screenshot of my sample app Navigation Drawer with Tab Strip Example at github

Navigation-drawer-page-sliding-tab-strip

Community
  • 1
  • 1
Balaji
  • 1,619
  • 15
  • 19