2015-08-28 84 views
0

我想爲android實現Path-like時間標記。我發現了一些關於如何在ListView上實現它的指南,但我需要爲RecyclerView做到這一點,其中包含不同大小的項目。 我該怎麼做?滾動條上的路徑狀標記

回答

0

我們用非常簡單和愚蠢的方法來實現時間路徑標記的流暢動畫。我們忽略了滾動條的真實位置,因爲它很難獲得,並且它傾向於根據內容大小大幅改變它的大小和位置。 在RecyclerView的OnScrolled方法中,我們根據dy重新計算並重置視圖邊距 - 所有像素都滾動。下面是代碼看起來像現在:

  @Override 
      public void onScrolled(RecyclerView recyclerView, int dx, int dy) { 
       super.onScrolled(recyclerView, dx, dy); 
       if (dy == 0) return; 
       if (dy < 0) { 
        if ((botMarg - dy) >= displayHeight - topOffset) { 
         botMarg = displayHeight - topOffset; 
        } else { 
         botMarg -= dy; 
        } 
       } else { 
        if (botMarg - dy <= botOffset) { 
         botMarg = botOffset; 
        } else { 
         botMarg -= dy; 
        } 
       } 

要得到我們使用的方法與recyclerView.findChildViewUnder()我們OnScrolled了位置當前視圖。