visual indication of over scroll in android

后端 未结 8 547
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-06 01:49

I am trying to add some visual indication, that there are no more pages in the desired fling direction in the ViewPager. However I am struggling to find a place, where to put re

8条回答
  •  攒了一身酷
    2021-02-06 02:38

    You have a lot of options, you can show a Toast, display a Dialog, make a TextView or image to appear over your UI, etc. Or because you know the amount of View items in the ViewPager, you could add different View at positions 0 and/or n + 1 with the message and make it bounce to the last View that actually contains your data.

    You could implement:

    viewPager.setOnPageChangeListener(new OnPageChangeListener() {
        public void onPageSelected(int position) {
            //TODO If position is the 0 or n item, add a view at 0 or at n+1 to indicate there is no more pages with data.
        }
    
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            // TODO Show a Toast, View or do anything you want when position = your first/last  item;
        }
    
        public void onPageScrollStateChanged(int state) {
        }
    });
    

提交回复
热议问题