2014-09-26 49 views
1

我想實現視圖隱藏的滾動的列表視圖。相對於在android中滾動的listview滑動視圖?

像Facebook應用程序: -

1)當列表視圖向下滾動,底部的藍色佈局(狀態,照片,簽入)開始相對於列表視圖滾動量向上滑動,最終變得可見

2.)當列表視圖向上滾動時,底部佈局向下滑動並最終隱藏。

3)當列表滾動向上和向下同時,佈局也相對於它

下滑及以上現在,我試圖通過翻譯來實現它,但結果是不太一樣: -

public void onScroll(AbsListView view, int firstVisibleItem, 
       int visibleItemCount, int totalItemCount) { 

      final int currentFirstVisibleItem = view.getFirstVisiblePosition(); 

      if (currentFirstVisibleItem > mLastFirstVisibleItem) { 
       // Scroll down 
       count = count + 20; 
      } else if (currentFirstVisibleItem < mLastFirstVisibleItem) { 
       // Scroll up 
       count = count - 20; 

      } 
      bottom.setTranslationY(count); 
      mLastFirstVisibleItem = currentFirstVisibleItem; 

     } 

使用此代碼,該視圖幻燈片但它不光滑。

+0

你試過加1而不是20嗎? – 2014-09-26 10:45:46

+0

1翻譯非常慢。當我在Facebook上滾動時,它非常流暢,通過滾動Feed只需稍微仰視即可快速上下移動 – 2014-09-26 10:47:05

回答

0

我在我的應用程序中做了類似的事情。除了我不滾動底部,而是滾動tabhost。也許你可以從這裏拿出一些代碼給你。

listView.setOnScrollListener(new AbsListView.OnScrollListener() 
    { 
     @Override 
     public void onScrollStateChanged(AbsListView absListView, int i) 
     { 
      if (i == SCROLL_STATE_IDLE) 
      { 
       mLastScroll = 0; 
       if (mTabHost.getTranslationY() >= -mTabHost.getHeight()/2) 
        mTabHost.animate().translationY(0).start(); 
       else 
        mTabHost.animate().translationY(-mTabHost.getHeight()).start(); 
      } 
     } 

     @Override 
     public void onScroll(AbsListView absListView, int i, int i2, int i3) 
     { 
      if (absListView.getChildCount() <= 0) 
       return; 
      View c = absListView.getChildAt(0); 
      int scrolly = -c.getTop() + absListView.getFirstVisiblePosition() * c.getHeight(); 
      if (mLastScroll == 0) 
       mLastScroll = (int)(scrolly + Math.round(mTabHost.getTranslationY()/0.7)); 
      float dif = 0; 
      if (mLastScroll - scrolly <= 0) 
       dif = mLastScroll - scrolly; 
      else 
       mLastScroll = scrolly; 

      if (dif * 0.7 < -mTabHost.getHeight()) 
      { 
       dif = Math.round(-mTabHost.getHeight()/0.7); 
       mLastScroll = (int) Math.round(scrolly - mTabHost.getHeight()/0.7); 
      } 
      mTabHost.setTranslationY(Math.round(dif * 0.7)); 
     } 
    });