我在我的應用中實現了SwipeRefreshLayout
和ViewPager
,但是存在很大的麻煩:每當我要向左/向右滑動以在頁面之間切換時,滾動過於敏感。輕掃一下也會觸發SwipeRefreshLayout
刷新。SwipeRefreshLayout + ViewPager,僅限水平滾動?
我想設置水平滑動開始時的限制,然後強制水平,直到刷卡結束。換句話說,我想在手指水平移動時取消垂直翻轉。
這個問題只發生在ViewPager
,如果我向下滑動,並且SwipeRefreshLayout
刷新功能被觸發(條形圖顯示),然後我水平移動手指,它仍然只允許垂直滑動。
我試圖延長ViewPager
類,但它不工作:
public class CustomViewPager extends ViewPager {
public CustomViewPager(Context ctx, AttributeSet attrs) {
super(ctx, attrs);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
boolean in = super.onInterceptTouchEvent(ev);
if (in) {
getParent().requestDisallowInterceptTouchEvent(true);
this.requestDisallowInterceptTouchEvent(true);
}
return false;
}
}
佈局的xml:
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/viewTopic"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.myapp.listloader.foundation.CustomViewPager
android:id="@+id/topicViewPager"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</android.support.v4.widget.SwipeRefreshLayout>
任何幫助,將不勝感激,謝謝
如果viewpager中的某個片段具有'SwipeRefreshLayout',那麼相同的場景是否可以工作? – Zapnologica 2015-05-24 10:14:10
https://androidbeasts.wordpress.com/2015/08/11/tabs-with-swipe-views/#more-79 – Aakash 2015-08-11 23:18:32