刷卡半页的ViewPager(从兼容包)ViewPager

2023-09-04 23:27:39 作者:埋葬て呐份爱

我使用的是 ViewPager PageAdapter (从兼容包V4)之间的水平列表刷卡箱。 的问题是,我从第一页第二个框是在第二页的第一个框(视觉上和概念上)。事情是这样的:

我做的方式,现在它的作品。然而,这变得有点怪异,因为在刷卡中间还有一种情况是,同一个盒子中出现两次(像它显示的图像)。

有一种方法可以刷卡只有一半页?

编辑:

盒是一个抽象的概念。其实每个盒子是一个的ListView 和创建不同的页面只是改变每个适配器的ListView

解决方案 创建每页一个片段 覆盖getPageWidth()的PageAdapter显示多个页面

code:

  @覆盖
公众持股量getPageWidth(INT位置){
    浮nbPages = 2; //你可以使用一个浮点值,显示部分页面
    收益率(1 / nbPages);
}
 

超详细 超炫酷的ViewPager框架 MaterialViewPager使用方法详解

I am using a ViewPager with a PageAdapter (from the compatibility pack v4) to swipe among a horizontal list of boxes. The problem is that my second box from the first page is the first box in the second page (visually and conceptually). Something like this:

The way I am doing now it works. However, this becomes kinda weird because at the middle of the swipe there is a situation that the same box appears twice (like it is shown in the image).

There is a way to swipe only "half" page?

EDIT:

The boxes are an abstraction. In fact each box is a ListView and I create different pages just changing the adapter of each ListView.

解决方案

Create one fragment per page Override getPageWidth() in PageAdapter to display more than one page

Code:

@Override
public float getPageWidth(int position) {
    float nbPages = 2; // You could display partial pages using a float value
    return (1 / nbPages);
}