2013-09-05 27 views
2

我正在使用Chris Banes提供的pullToRefreshLibrary。我有gridView包含整個數據列表。我嘗試過pullToRefreshGridViewActivity,但它太慢,所以我想通過我的gridView使用pullToRefreshScrollViewActivity來處理它。問題是,當我這樣做時,scrollView正在處理所有觸摸事件,我無法滑過gridView。我需要鎖定它並將觸摸傳遞給gridView。 這裏是我的xml:如何從傾聽觸摸禁用pullToRefreshScrollView

<com.handmark.pulltorefresh.library.PullToRefreshScrollView 
     xmlns:ptr="http://schemas.android.com/apk/res-auto" 
     android:id="@+id/pull_refresh_scrollview" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     ptr:ptrAnimationStyle="flip" > 

     <com.asd.android.dda.ui.controls.ExpandableGridView 
      android:id="@+id/gridview" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:clipToPadding="false" 
      android:drawSelectorOnTop="true" 
      android:fadingEdge="none" 
      android:gravity="top" 
      android:horizontalSpacing="@dimen/image_grid_hspacing" 
      android:listSelector="@drawable/selector_shadow" 
      android:numColumns="@integer/grid_num_cols" 
      android:paddingBottom="50dp" 
      android:scrollbarAlwaysDrawVerticalTrack="false" 
      android:scrollbars="none" 
      android:scrollingCache="true" 
      android:smoothScrollbar="false" 
      android:stretchMode="columnWidth" 
      android:verticalSpacing="@dimen/image_grid_vspacing" 
      android:visibility="visible" /> 
    </com.handmark.pulltorefresh.library.PullToRefreshScrollView> 

我試圖與鎖定滾動視圖:

mScrollView.requestDisallowInterceptTouchEvent(true); 
gridView.requestDisallowInterceptTouchEvent(true); 

mScrollView.setOnTouchListener(new OnTouchListener(){ 
    @Override 
    public boolean onTouch(View v, MotionEvent event) { 
     return false; 
    } 
}); 
mScrollView.setOnTouchListener(null); 

但所有這些工作。我不能在這裏使用自定義ScrollView來覆蓋onInterceptTouchEvent。

+0

定義「太慢」。這聽起來很奇怪,因爲它幾乎被認爲是用於這種用途 – njzk2

+0

它是一個非常大的圖像數據庫,連續兩個和相當大的列表。我已經將它與GridView的拉到刷新實現進行了比較,並且它顯然較慢。這可能是GridView風格的修改。這就是爲什麼我想要使用ScrollView,只有當用戶位於GridView之上時,才能打開觸摸屏。 –

+1

這個庫似乎依賴於在gridlayout中將gridview放在一個線性佈局中,原因很多,我不太明白。我會說拉刷新網格視圖可能很簡單:當網格的頂部已經顯示時檢測垂直拖動手勢。 – njzk2

回答

0

你可以使用的一個破解是打開庫,從onInterceptTouchEvent等方法進入PullToRefreshBase.java並刪除final。然後您可以使用自定義ScrollView。