Indicate after swiping the last page in ViewPager
Asked Answered
B

2

3

I have created a view pager with circle page indicator. Its working fine. Here is my new requirement : When i'am in last/first page and try to swipe for next/previous page, my screen should move at least 30% towards the swiped direction and come back to its original position as there are no more pages to navigate? Of course i have page indicators at top which tells where am i in available pages. I hope my requirement is clear. How can i achieve it ? Please help me. Thanks in advance.

Blakemore answered 22/10, 2012 at 12:48 Comment(0)
S
2

This is automatic. The OS has built in indicators to tell the user the views can't be swiped any further. The OS will display a glow on the side of the screen, and the user can't pull further.

Not sure if you can create your own unique UI to handle this - the OS does provide a indicator out of the box.

Schenk answered 22/10, 2012 at 13:3 Comment(3)
Unless I somehow accidentally turned it off, I've used ViewPager for months and it has never automatically done an overswipe effect. It does do it for GridView, TextView, and ListView though.Bing
this depended on the OS, i check this with 2.3 & 4.1 devices and the implementation is different. in 2.3 there no indication at all , in 4.1 there is glow side affect, I believe you will have to implement this by yourselfDenicedenie
FWIW - this is called "Overscroll"Schenk
F
6
ViewPager.OnPageChangeListener pagerListener = new ViewPager.OnPageChangeListener() {
        boolean lastPageChange = false;

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels){
            int lastIdx = mPgScreenAdapter.getCount() - 1;

            Log.d(TAG, "pos:" + position);
            if(lastPageChange && position == lastIdx)
                PPIntent.changeScene(curAct, new Intent(curAct, LoginActivity.class), true);
        }
        @Override
        public void onPageSelected( int i) {
            pgText.setCurrentItem(i/2);
        }
        @Override
        public void onPageScrollStateChanged(int state) {
            int lastIdx = mPgScreenAdapter.getCount() - 1;

            int curItem = pgScreen.getCurrentItem();
            if(curItem==lastIdx /*&& lastPos==lastIdx*/  && state==1)   lastPageChange = true;
            else                                                         lastPageChange = false;
        }
    };
Factory answered 19/3, 2015 at 4:30 Comment(2)
This works well , just that the code to start a new activity can be moved to pagescrollstatechanged inside the if condition since, onPageScrolled gets called multiple times..Bhang
Can you tell me how to toast ("this is first page") to user if user swipe first page of viewpager in backward direction.Thank you @FactoryHildagarde
S
2

This is automatic. The OS has built in indicators to tell the user the views can't be swiped any further. The OS will display a glow on the side of the screen, and the user can't pull further.

Not sure if you can create your own unique UI to handle this - the OS does provide a indicator out of the box.

Schenk answered 22/10, 2012 at 13:3 Comment(3)
Unless I somehow accidentally turned it off, I've used ViewPager for months and it has never automatically done an overswipe effect. It does do it for GridView, TextView, and ListView though.Bing
this depended on the OS, i check this with 2.3 & 4.1 devices and the implementation is different. in 2.3 there no indication at all , in 4.1 there is glow side affect, I believe you will have to implement this by yourselfDenicedenie
FWIW - this is called "Overscroll"Schenk

© 2022 - 2024 — McMap. All rights reserved.