ViewPager禁用刷到一定方向 [英] ViewPager disable swiping to a certain direction

查看:140
本文介绍了ViewPager禁用刷到一定方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要禁用刷卡,但只有右侧。我发现这的答案。遗憾的是,这份全 ViewPager 源要达到的目标。有刚继承现有类,而不是复制的任何方法?

I want to disable the swiping, but only to the right side. I found a working solution in this answer. Unfortunately, this copies the whole ViewPager source to achieve the goal. Is there any methods just inheriting the existing class and not duplicating?

推荐答案

我不知道这正是你需要: 我需要一个viewpager为与最大页面向导,用户无法通过。

I'm not sure this is exactly what you need: I needed a viewpager for a wizard with a max page that the user can't pass it.

目前终了时,溶液是在适配器。 我改变了PagerAdapter的数量,这种方式阻止用户从通过最大页面:

At the end the solution was in the adapter. I changed the count of the PagerAdapter and this way blocks the user from passing the max page:

@Override
public int getCount() {
    return mProgress; //max page + 1
}

当用户前进到下一个页面:

When the user progresses to the next page:

private void setWizardProgress(int progress) {
    if(progress > mProgress) {
        mProgress = progress;
        mWizardPagerAdapter.notifyDataSetChanged();
    }
}

这样当用户在最大页,他不能滚动到右侧。

This way when the user is at max page he can't scroll to the right.

这篇关于ViewPager禁用刷到一定方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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