Multiple pages at the same time on a ViewPager

前端 未结 8 1437
执念已碎
执念已碎 2020-12-07 09:58

Is there a possibility to display two pages at the same time, when using a ViewPager? I\'m not looking for an edge effect, but rather for two full

8条回答
  •  日久生厌
    2020-12-07 10:57

    See my more up-to-date answer here: Can ViewPager have multiple views in per page?

    I discovered that a perhaps even simpler solution through specifying a negative margin for the ViewPager. I've created the MultiViewPager project on GitHub, which you may want to take a look at:

    https://github.com/Pixplicity/MultiViewPager

    Although this question specifically asks for a solution without edge effect, some answers here propose the workaround by CommonsWare, such as the suggestion by kaw.

    There are various problems with touch handling and hardware acceleration with that particular solution. A simpler and more elegant solution, in my opinion, is to specify a negative margin for the ViewPager:

    ViewPager.setPageMargin(
        getResources().getDimensionPixelOffset(R.dimen.viewpager_margin));
    

    I then specified this dimension in my dimens.xml:

    -64dp
    

    To compensate for overlapping pages, each page's content view has the opposite margin:

    android:layout_marginLeft="@dimen/viewpager_margin_fix"
    android:layout_marginRight="@dimen/viewpager_margin_fix"
    

    Again in dimens.xml:

    32dp
    

    (Note that the viewpager_margin_fix dimension is half that of the absolute viewpager_margin dimension.)

    We implemented this in the Dutch newspaper app De Telegraaf Krant:

    Phone example in De Telegraaf KrantTablet example

提交回复
热议问题