1

I want to implement two vertical list views A and B such that only 1 of them is visible at a time and a horizontal scroll shows the next list.

I want the scrolling to be smooth ie while you touch down and move your finger the present list moves along and the new list moves in ... the effect while moving images in gallery.

I have been able to scroll bw the views and with the use of translate animation am being able to show the smooth transition but what I want to achieve is the gallery like effect.

So horizontal scroll switches bw diff list views and vertical scroll can be used to scroll through the list.

pvn
  • 2,016
  • 19
  • 33

1 Answers1

3

You could use a ViewPager to accomplish this. http://developer.android.com/reference/android/support/v4/view/ViewPager.html

main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1" />

</LinearLayout>

MainActivity.java

....

onCreate()...
 mViewPager = (ViewPager) findViewById(R.id.pager);

            mViewPager.setAdapter(new HomePagerAdapter(getSupportFragmentManager()));
//If your Activity implements ViewPager.OnPageChangeListener
  //          mViewPager.setOnPageChangeListener(this);
...

private class HomePagerAdapter extends FragmentPagerAdapter {
    public HomePagerAdapter(FragmentManager fm) {
        super(fm);
    }

    @Override
    public Fragment getItem(int position) {
        switch (position) {
            case 0:
                return (mMyListViewFragment1 = new MyListViewFragment());

            case 1:
                return (mMyListViewFragment2 = new MyListViewFragment());

        }
        return null;
    }

    @Override
    public int getCount() {
        return 2;
    }
}
TouchBoarder
  • 6,422
  • 2
  • 52
  • 60
  • Will verticall scroll in the listView work if I use that ... lemme chkout – pvn Jan 11 '13 at 06:45
  • 2
    It will work. This is the way even Google Play has implemented it. I mean the PlayStore app on Android – Sudarshan Bhat Jan 11 '13 at 06:52
  • A doubt in getItem() .... won't there be return type error coz the ret type specified is Fragment whereas the returned obj is either mMyListViewFragment1 and mMyListViewFragment2. – pvn Jan 11 '13 at 10:14
  • They are both Fragment, but an extended version of Fragment. ->ListFragment – TouchBoarder Jan 11 '13 at 12:08