0

I'd like to implement something like that (see the image) in Android. What's the best and easiest way to achieve this design? Listviews in a listview, perhaps?

enter image description here

burakk
  • 1,231
  • 2
  • 22
  • 45

2 Answers2

4

I would recomend using ViewPager with listViews

http://developer.android.com/training/animation/screen-slide.html

http://developer.android.com/reference/android/support/v4/view/ViewPager.html

Your list and other categories (if I understand correctly your diagram) would be implemented in a form of Fragments.

marcinj
  • 48,511
  • 9
  • 79
  • 100
4

From your image I believe you're looking for "swiping tabs". The tabs aren't required though, just swiping views is also possible. Swiping views is done with the ViewPager component.

If you google "android swiping tabs" you'll get to this android design article with the perfect title Creating Swipe Views with Tabs.

The magic happens in these lines of code:

@Override
public void onCreate(Bundle savedInstanceState) {
    ...

    // Create a tab listener that is called when the user changes tabs.
    ActionBar.TabListener tabListener = new ActionBar.TabListener() {
        public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) {
            // When the tab is selected, switch to the
            // corresponding page in the ViewPager.
            mViewPager.setCurrentItem(tab.getPosition());
        }
        ...
    };
}

The linked article has a complete example available for download so I won't go into more detail here.

Free tip: Also look into Fragments if you're not familiar with that.

hcpl
  • 17,382
  • 7
  • 72
  • 73
  • I see, thanks. But how am I going to display the edges of the next tab and fragment? Any ideas? – burakk Feb 03 '14 at 10:05
  • each fragment has 1 listView. No need to nest listviews for this. The fragments in your viewpager can have borders. Also there is a padding option. Check this question and answers for more info on the padding: http://stackoverflow.com/questions/7343487/android-viewpager-padding-margin-between-page-fragments – hcpl Feb 03 '14 at 10:08
  • If I understand correctly, both fragments, the fragment containing the tabs and the fragment below, containing the listview will be controlled by two different viewpagers, and I'll need to call setPageMargin(int) on both viewpagers... Is that correct? – burakk Feb 03 '14 at 10:15