ViewPager - get a partial view of the next page

后端 未结 5 693
既然无缘
既然无缘 2020-12-07 11:32

I am trying to achieve this in a ViewPager

The first fragment (blue) is displayed and the beginning of the next fragment must be displayed as well, so the user under

相关标签:
5条回答
  • 2020-12-07 11:48
    viewpager.setClipToPadding(false);
    viewpager.setPageMargin(-50);
    
    0 讨论(0)
  • 2020-12-07 11:56

    Try using a negative value for ViewPager.setPageMargin.

    0 讨论(0)
  • 2020-12-07 11:59

    You can try adding this to your PageAdapter:

    public float getPageWidth(int position) {
        if (position == 0 || position == 2) {
            return 0.8f;
        }
        return 1f;
    }
    
    0 讨论(0)
  • 2020-12-07 12:07
    @Override
    public float getPageWidth(int position) {
        return 0.9f;
    }
    

    Use this, this will work perfectly and make sure that your class extended to PagerAdapter

    0 讨论(0)
  • 2020-12-07 12:08

    This function worked better than the answer marked as correct (for me anyway).

    @Override
    public float getPageWidth(int position) {
        return 0.9f;
    }
    

    Just place it in your custom PagerAdapter class.

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