Spotify ListView header image effect

后端 未结 4 415
无人共我
无人共我 2020-12-23 00:24

The Android version of Spotify has a unique ListView header effect when viewing an artist. Basically the header image appears to maintain it\'s own scrolling speed apart fro

4条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-23 00:48

    It is simply done like this, assuming you have a scrollview containing an imageview that you both have references to:

       scrollView.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {
            @Override
            public void onScrollChanged() {
                        int top = scrollView.getScrollY(); // Increases when scrolling up ^
                        int newTop = (int) (top * .5f);
                        imageFrame.setTranslationY(newTop < 0 ? 0 : newTop);
    
            }
        });
    

    This will scroll the imageview upwards at half speed compared to the rest of the scrollview, and also checks that it never scrolls down more than it should (past 0)

提交回复
热议问题