国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

PullToRefreshScrollView嵌套viewpager

2019-11-09 14:44:05
字體:
來源:轉載
供稿:網友

項目需要實現功能:頁面下拉刷新,上拉加載,頁面內部有無線輪播。

實現方式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()方法,
@OverridePRotected 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"-->            <!--&gt;</appliaction.yll.com.myapplication.ui.view.MyPager>-->    </LinearLayout></com.handmark.pulltorefresh.library.PullToRefreshScrollView>這樣,viewpager顯示正常了,但是上下滑動時有事件沖突。

只好改寫viewpager的dispatchTouchEvent(MotionEvent ev),代碼如下:

@Overridepublic 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)){                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事件中,這樣就可以實現功能需求啦。


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 乐昌市| 鄱阳县| 富锦市| 五河县| 永修县| 阿鲁科尔沁旗| 亚东县| 富源县| 广平县| 南川市| 巫溪县| 乌兰察布市| 当阳市| 龙川县| 黄大仙区| 长沙县| 灵武市| 镇坪县| 图木舒克市| 潼南县| 宿迁市| 朔州市| 固镇县| 台东县| 花莲市| 吴江市| 芮城县| 江油市| 隆德县| 富锦市| 商丘市| 抚松县| 德化县| 漾濞| 叶城县| 凤冈县| 孟连| 依兰县| 临潭县| 上栗县| 正定县|