2014-09-19 10 views
0

我使用的是接下來的源代碼,以向上滾動,滾動型向上滾動滾動型,但我已經看到,該方法removeOnGlobalLayoutListener沒有受到API 16試圖在所有API

public void scrollUp(){ 
     // Wait until my scrollView is ready 
     sv_container.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { 
      @Override 
      public void onGlobalLayout() { 
       // Ready, move up 
       sv_container.fullScroll(View.FOCUS_UP); 
       sv_container.getViewTreeObserver().removeOnGlobalLayoutListener(this); 
      } 
     }); 
    } 

兼容您是否知道在所有API中實現此目的的方法?謝謝

回答

0

解決:

public void scrollUp(){ 
     // Wait until my scrollView is ready 
     sv_container.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { 
      @Override 
      public void onGlobalLayout() { 
       // Ready, move up 
       sv_container.fullScroll(View.FOCUS_UP); 
       if(Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) { 
        sv_container.getViewTreeObserver().removeGlobalOnLayoutListener(this); 
       } else { 
        sv_container.getViewTreeObserver().removeOnGlobalLayoutListener(this); 
       } 
      } 
     }); 
    } 
相關問題