How to swipe xml layouts using ViewPager

后端 未结 2 1641
一个人的身影
一个人的身影 2021-01-25 06:27

I am building an app in which I want to enable swipe. I want to swipe xml layouts but in a single activity. Earlier I tried to put images, it worked. I created an ImageAdapter c

相关标签:
2条回答
  • 2021-01-25 07:05

    For your first question, the Infinite Scrolling, I figured out one solution to it.

    Here's how I am doing it:

    No looping is required in this case. No matter what your getCount() is.

    After setting the adapter, I am setting a setOnPageChangeListener to the view pager like this:

    myPager.setOnPageChangeListener(new OnPageChangeListener() {
    
                    @Override
                    public void onPageSelected(int position) {
    //Define the focused page before your onCreate()..private int focusedPage = 0;
                        focusedPage = position;
                    }
                    //We don't have to do anything here.
                    @Override
                    public void onPageScrolled(int arg0, float arg1, int arg2) {
                        // TODO Auto-generated method stub
    
                    }
                    //Here's where the magic is. After you reach the end of the page, you can scroll again and it will move your view to page 1 again.
                    @Override
                    public void onPageScrollStateChanged(int arg0) {
    
                        myPager.setCurrentItem(0,false);
    
                    }
                });
    

    See if this solution works.. It's working perfect for me. .:D

    0 讨论(0)
  • 2021-01-25 07:14

    enter image description hereI have answered a similar question here :

    How to use swipe gesture in a view pager's page with android? enter image description here Take a look at that and you will get what you are looking for.

    Hope that helps .. and don't forget to accept my answer :)

    Here's the images for that:

    http://imageshack.com/a/img547/6988/cpr5.png

    http://imageshack.com/a/img198/2594/tp58.png

    Here's what I found for your first question. Its the infinite scrolling. Its a good post here:

    Changing ViewPager to enable infinite page scrolling

    0 讨论(0)
提交回复
热议问题