在 ViewPager 中滑动半页(来自兼容包) [英] Swipe half page in a ViewPager (from compatibility pack)

查看:15
本文介绍了在 ViewPager 中滑动半页(来自兼容包)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用带有 PageAdapter(来自兼容包 v4)的 ViewPager 在水平框列表之间滑动.问题是我的第一页中的第二个框是第二页中的第一个框(从视觉上和概念上).像这样的:

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).

有办法只刷半"页吗?

盒子是一种抽象.实际上每个盒子都是一个 ListView 我创建不同的页面只是改变每个 ListView 的适配器.

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

推荐答案

  1. 每页创建一个片段
  2. 重写 PageAdapter 中的 getPageWidth() 以显示多个页面

代码:

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

这篇关于在 ViewPager 中滑动半页(来自兼容包)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆