SupportV7包中 SwipeRefreshLayout 修改下拉控件的距离

 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         });

 

posted @ 2015-08-03 17:58  谈笑风生膜法师  阅读(666)  评论(0编辑  收藏  举报