1 //修改下拉距离 2 ViewTreeObserver vto = mCategoryResults.mSwipeRefreshLayout.getViewTreeObserver(); 3 vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { 4 public void onGlobalLayout() { 5 6 final DisplayMetrics metrics = getResources().getDisplayMetrics(); 7 Float mDistanceToTriggerSync = Math.min(((View) mCategoryResults.mSwipeRefreshLayout.getParent()).getHeight() * 0.6f, 500 * metrics.density); 8 9 try { 10 Field field = SwipeRefreshLayout.class.getDeclaredField("mDistanceToTriggerSync"); 11 field.setAccessible(true); 12 field.setFloat(mCategoryResults.mSwipeRefreshLayout, mDistanceToTriggerSync); 13 } catch (Exception e) { 14 e.printStackTrace(); 15 } 16 ViewTreeObserver obs = mCategoryResults.mSwipeRefreshLayout.getViewTreeObserver(); 17 obs.removeOnGlobalLayoutListener(this); 18 } 19 });