How to create carousel ViewPager?

前端 未结 3 1549
梦毁少年i
梦毁少年i 2021-02-04 17:20

All I want to do is a horizontal carousel in Android.

If I have 3 screens A B and C then I want my ViewPager to allow me to move like A <-> B, B <-> C, C <->

3条回答
  •  旧巷少年郎
    2021-02-04 17:30

    Implement the getItem(int position) like this:

    public Fragment getItem(int position)
    {
        switch(position)
        {
            case 0:
            Fragment A = new A();
            return A;
            case 1:
            Fragment B = new B();
            return B;
            same for C....
        }
    }
    

    you can also have a look at here: SimpleViewPager.. download the source and understand it. Hope it helps.

提交回复
热议问题