0

Android studio has these blank activity navigation examples - Swipe Views (ViewPager) and Navigation Drawer.

My goal is to make an application which has both of these navigation types to traverse the collection of data.

Example

The most basic example of the wanted behavior would be an application containing 15 articles. When the application is opened user sees the first article. Then the user can either open the Navigation Drawer and select on of the articles OR use swipe to go to the next article.

Any ideas or examples are welcome.

Background

I am building an app for Android 4.0+

Laurynas Mališauskas
  • 1,909
  • 1
  • 19
  • 34

1 Answers1

1

You've already mentioned both of the necessary widgets. Implement a NavigationDrawer, and use a ViewPager as the main content view as described in the NavigationDrawer documentation.

Edit:

Set your content view using an XML similar to the following:

XML

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

        <android.support.v4.view.ViewPager
            android:id="@+id/tutorial_pager"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_alignParentTop="true" />

    <ListView
        android:id="@+id/app_drawer_left"
        android:layout_width="@dimen/navigation_drawer_width"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="@color/off_white"
        android:choiceMode="singleChoice"
        android:divider="@drawable/horizontal_divider_dashed"
        android:dividerHeight="1dip" />

</android.support.v4.widget.DrawerLayout>

Then just set up your activity as you would when using a ViewPager/ListView.

Submersed
  • 8,810
  • 2
  • 30
  • 38
  • i am trying to do just that, but without success. Do you have any working example? – Laurynas Mališauskas Jan 16 '14 at 16:40
  • Yeah, I do, but I can't really share it as is. The two can definitely be implemented together. Also, if you post what you've already tried/issues you're having, it would be easier to help. – Submersed Jan 16 '14 at 17:02
  • only now i understood that i tried to do just the opposite way. Imade the ViewPager my MainActovity layout and added NavigationDrawer inside it. I will try to make it now the way you told me and post here if i have any problems. – Laurynas Mališauskas Jan 16 '14 at 17:10