viewPager滑动到最后一张怎么进入下个页面
2个回答
展开全部
public class LastPageJumpListener implements OnPageChangeListener {
private int lastIndex;
private Runnable command;
/**
* 是否可以跳转
*/
private boolean canJump;
private int curPosition;
/**
* @param lastIndex
* 最后一页的索引
* @param command
* 事件触发时你想要做的事情
*/
public LastPageJumpListener(int lastIndex, Runnable command) {
this.lastIndex = lastIndex;
this.command = command;
}
@Override
public void onPageScrolled(int position, float positionOffset,
int positionOffsetPixels) {
Log.e(TAG, "onPageScrolled position:" + position);
//当最后一页往后划动的时候触发该事件
if (position == lastIndex && positionOffset == 0
&& positionOffsetPixels == 0) {
if (canJump) {
command.run();
// 事件执行一次后进行重置,避免事件多次触发
canJump = false;
}
}
}
/*
* (non-Javadoc)
*
* @see
* android.support.v4.view.ViewPager.OnPageChangeListener#onPageSelected
* (int)
*/
@Override
public void onPageSelected(int position) {
curPosition = position;
}
/**
* public static final int SCROLL_STATE_IDLE = 0;
*
* public static final int SCROLL_STATE_DRAGGING = 1;
*
* public static final int SCROLL_STATE_SETTLING = 2;
*/
@Override
public void onPageScrollStateChanged(int state) {
Log.e(TAG, "onPageScrollStateChanged state:" + state);
// 判断是否是划动状态且是最后一页
if (state == ViewPager.SCROLL_STATE_DRAGGING
&& curPosition == lastIndex) {
canJump = true;
} else {
canJump = false;
}
}
}
这是我自己写的,实测可以用,不懂你可以问我
private int lastIndex;
private Runnable command;
/**
* 是否可以跳转
*/
private boolean canJump;
private int curPosition;
/**
* @param lastIndex
* 最后一页的索引
* @param command
* 事件触发时你想要做的事情
*/
public LastPageJumpListener(int lastIndex, Runnable command) {
this.lastIndex = lastIndex;
this.command = command;
}
@Override
public void onPageScrolled(int position, float positionOffset,
int positionOffsetPixels) {
Log.e(TAG, "onPageScrolled position:" + position);
//当最后一页往后划动的时候触发该事件
if (position == lastIndex && positionOffset == 0
&& positionOffsetPixels == 0) {
if (canJump) {
command.run();
// 事件执行一次后进行重置,避免事件多次触发
canJump = false;
}
}
}
/*
* (non-Javadoc)
*
* @see
* android.support.v4.view.ViewPager.OnPageChangeListener#onPageSelected
* (int)
*/
@Override
public void onPageSelected(int position) {
curPosition = position;
}
/**
* public static final int SCROLL_STATE_IDLE = 0;
*
* public static final int SCROLL_STATE_DRAGGING = 1;
*
* public static final int SCROLL_STATE_SETTLING = 2;
*/
@Override
public void onPageScrollStateChanged(int state) {
Log.e(TAG, "onPageScrollStateChanged state:" + state);
// 判断是否是划动状态且是最后一页
if (state == ViewPager.SCROLL_STATE_DRAGGING
&& curPosition == lastIndex) {
canJump = true;
} else {
canJump = false;
}
}
}
这是我自己写的,实测可以用,不懂你可以问我
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
网易云信
2023-12-06 广告
2023-12-06 广告
很高兴能回答您的问题。以下是一段针对“一对一消息组件”的描述,字数在200字左右:该组件支持用户之间的私密交流,让沟通更加直接和高效。通过它,您可以向特定对象发送消息,并实时查看消息状态,包括对方是否已读或未读。同时,该组件还支持富文本消息...
点击进入详情页
本回答由网易云信提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询