本文实例讲述了Android编程中ViewPage判断左右滑动方向的方法。分享给大家供大家参考,具体如下: package com.meityitian.app.views;
本文实例讲述了Android编程中ViewPage判断左右滑动方向的方法。分享给大家供大家参考,具体如下:
package com.meityitian.app.views;
import android.content.Context;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.util.Log;
import com.meityitian.app.utils.Debug;
public class meityitianViewPager extends ViewPager {
private boolean left = false;
private boolean right = false;
private boolean isScrolling = false;
private int lastValue = -1;
private ChangeViewCallback changeViewCallback = null;
public meityitianViewPager(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public meityitianViewPager(Context context) {
super(context);
init();
}
private void init() {
setOnPageChangeListener(listener);
}
public OnPageChangeListener listener = new OnPageChangeListener() {
@Override
public void onPageScrollStateChanged(int arg0) {
if (arg0 == 1) {
isScrolling = true;
} else {
isScrolling = false;
}
Debug.infoByTag("meityitianViewPager",
"meityitianViewPager onPageScrollStateChanged : arg0:"
+ arg0);
if (arg0 == 2) {
Debug.infoByTag("meityitianViewPager",
"meityitianViewPager onPageScrollStateChanged direction left ? "
+ left);
Debug.infoByTag("meityitianViewPager",
"meityitianViewPager onPageScrollStateChanged direction right ? "
+ right);
//notify ....
if(changeViewCallback!=null){
changeViewCallback.changeView(left, right);
}
right = left = false;
}
}
@Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
if (isScrolling) {
if (lastValue > arg2) {
// 递减,向右侧滑动
right = true;
left = false;
} else if (lastValue < arg2) {
// 递减,向右侧滑动
right = false;
left = true;
} else if (lastValue == arg2) {
right = left = false;
}
}
Log.i("meityitianViewPager",
"meityitianViewPager onPageScrolled last :arg2 ,"
+ lastValue + ":" + arg2);
lastValue = arg2;
}
@Override
public void onPageSelected(int arg0) {
if(changeViewCallback!=null){
changeViewCallback.getCurrentPageIndex(arg0);
}
}
};
public boolean getMoveRight(){
return right;
}
public boolean getMoveLeft(){
return left;
}
public interface ChangeViewCallback{
public void changeView(boolean left,boolean right);
public void getCurrentPageIndex(int index);
}
public void setChangeViewCallback(ChangeViewCallback callback){
changeViewCallback = callback;
}
}
希望本文所述对大家Android程序设计有所帮助。
您可能感兴趣的文章:Android中实现监听ScrollView滑动事件android 通过向viewpage中添加listview来完成滑动效果(类似于qq滑动界面)解析Android中实现滑动翻页之ViewFlipper的使用详解Android中实现水平滑动(横向滑动)ListView示例Android利用ViewPager实现滑动广告板实例源码Android App中使用ViewPager+Fragment实现滑动切换效果Android中RecyclerView实现横向滑动代码android配合viewpager实现可滑动的标签栏示例分享Android App中ViewPager所带来的滑动冲突问题解决方法Android实现View滑动的6种方式
--结束END--
本文标题: Android编程中ViewPage判断左右滑动方向的方法
本文链接: https://lsjlt.com/news/26397.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-01-21
2023-10-28
2023-10-28
2023-10-27
2023-10-27
2023-10-27
2023-10-27
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0