PullToRefreshScrollView嵌套viewpager
2017-02-10 17:29
471 查看
项目需要实现功能:页面下拉刷新,上拉加载,页面内部有无线轮播。
实现方式1:
github上下载一个无限轮播的控件,嵌套到PullToRefreshScrollView中。
轮播图显示出来了,可是高度不对。
然后 在控件外面再套层布局,如下:
这样,viewpager显示正常了,但是上下滑动时有事件冲突。
只好改写viewpager的dispatchTouchEvent(MotionEvent ev),代码如下:
在这里遇到问题————在竖向滑动的时候,父控件可以拦截事件,viewpager获取不到up事件,无法让轮播图startAotoLoop(),想到办法就是将这个方法放到move事件中,这样就可以实现功能需求啦。
实现方式1:
github上下载一个无限轮播的控件,嵌套到PullToRefreshScrollView中。
<com.handmark.pulltorefresh.library.PullToRefreshScrollView android:layout_width="match_parent" android:layout_height="match_parent"> <!--第一个轮播--> <com.kevin.loopview.AdLoopView android:id="@+id/main_act_adloopview" android:layout_width="match_parent" android:layout_height="400dp" > </com.kevin.loopview.AdLoopView> </com.handmark.pulltorefresh.library.PullToRefreshScrollView> 这样写的问题是,viewpager不显示。 然后我重写了viewpager的onmeasure()方法,
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int height = 0; for(int i = 0; i < getChildCount(); i++) { View child = getChildAt(i); child.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(300, MeasureSpec.EXACTLY)); int h = child.getMeasuredHeight(); if(h > height) height = h; } heightMeasureSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY); super.onMeasure(widthMeasureSpec, heightMeasureSpec); }
轮播图显示出来了,可是高度不对。
然后 在控件外面再套层布局,如下:
<com.handmark.pulltorefresh.library.PullToRefreshScrollView android:layout_width="match_parent" android:layout_height="match_parent"> <!--第一个轮播--> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent"> <com.kevin.loopview.AdLoopView android:id="@+id/main_act_adloopview" android:layout_width="match_parent" android:layout_height="400dp" > </com.kevin.loopview.AdLoopView> <!--<appliaction.yll.com.myapplication.ui.view.MyPager--> <!--android:id="@+id/search_viewpager"--> <!--android:layout_width="match_parent"--> <!--android:layout_height="300dp"--> <!--android:background="@color/red"--> <!--></appliaction.yll.com.myapplication.ui.view.MyPager>--> </LinearLayout> </com.handmark.pulltorefresh.library.PullToRefreshScrollView>
这样,viewpager显示正常了,但是上下滑动时有事件冲突。
只好改写viewpager的dispatchTouchEvent(MotionEvent ev),代码如下:
@Override public boolean dispatchTouchEvent(MotionEvent ev) { int action = MotionEventCompat.getActionMasked(ev); switch (ev.getAction()){ case MotionEvent.ACTION_DOWN: if(isAutoScroll){ isStopByTouch = true; stopAutoLoop(); Log.d("dddd", "dispatchTouchEvent: down1"); } Log.d("dddd", "dispatchTouchEvent: down2"); x = ev.getX(); y = ev.getY(); break; case MotionEvent.ACTION_MOVE: float moveX = ev.getX(); float moveY = ev.getY(); if(Math.abs(moveY- y)>Math.abs(moveX- x 91ab )){ getParent().requestDisallowInterceptTouchEvent(false); if(isStopByTouch){ startAutoLoop(mInterval); Log.d("dddd", "dispatchTouchEvent: up1"); } break; }else{ getParent().requestDisallowInterceptTouchEvent(true); } Log.d("dddd", "dispatchTouchEvent: move"); break; case MotionEvent.ACTION_UP: getParent().requestDisallowInterceptTouchEvent(true); if(isStopByTouch){ startAutoLoop(mInterval); Log.d("dddd", "dispatchTouchEvent: up1"); } Log.d("dddd", "dispatchTouchEvent: up2"); break; }
在这里遇到问题————在竖向滑动的时候,父控件可以拦截事件,viewpager获取不到up事件,无法让轮播图startAotoLoop(),想到办法就是将这个方法放到move事件中,这样就可以实现功能需求啦。
相关文章推荐
- 使用pulltorefreshscrollview 嵌套 listview viewpager的配置方式
- PullToRefreshScrollView 嵌套 ViewPager 冲突导致界面不显示的问题
- 占位布局之fragment01的布局---PullToRefreshScrollView+viewpager+listview
- PullToRefreshScrollView 嵌套RecyclerView实现特卖列表倒计时抢购
- 当PullToRefreshScrollView里面嵌套ListView
- 当PullToRefreshScrollView里面嵌套ListView,下拉刷新时ListView主动向上滑
- 利用android-Ultra-Pull-To-Refresh做的下拉刷新,支持viewpager等view完美嵌套
- PullToRefreshScrollView 嵌套RecyclerView实现特卖列表倒计时抢购
- PullToRefreshScrollView 嵌套RecyclerView实现特卖列表倒计时抢购
- android PullToRefreshScrollView中 嵌套viewpage 解决不显示的问题
- PullToRefreshScrollView嵌套两个GridView
- Android_横向滑动菜单, HorizontalScrollView,Fragment,Viewpager结合使用 +pullToRefreshListView
- 如何PullToRefreshScrollView里面嵌套GridView
- 当PullToRefreshScrollView里面嵌套ListView
- PullToRefreshScrollView 嵌套RecyclerView实现特卖列表倒计时抢购
- pulltorefresh+viewpager fragment+HorizontalScrollView
- Android PullToRefreshScrollView、AutoHeightListView、AutoScrollViewPager的使用
- PullToRefreshScrollView+ViewPager+MyListView
- PullToRefreshScrollView 嵌套gridview或listView,顶部布局顶上去的问题处理
- AutoScrollViewPager与PullToRefreshScrollView冲突解决