ViewPager - get a partial view of the next page

Deadly 提交于 2019-12-17 17:24:47

问题


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 understands he can swipe to switch views. The idea is scroll 20% of the screen programmatically to the left.

Any thoughts are welcome

EDIT: This is exactly what I need to to: the central view needs to overlap both side views


回答1:


You can try adding this to your PageAdapter:

public float getPageWidth(int position) {
    if (position == 0 || position == 2) {
        return 0.8f;
    }
    return 1f;
}



回答2:


Try using a negative value for ViewPager.setPageMargin.




回答3:


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.




回答4:


viewpager.setClipToPadding(false);
viewpager.setPageMargin(-50);


来源:https://stackoverflow.com/questions/9907748/viewpager-get-a-partial-view-of-the-next-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!