Imageview parallax as you scroll

后端 未结 2 2042
情书的邮戳
情书的邮戳 2020-12-13 03:42

I saw many examples demonstrative parallax background as you scroll or listview parallax but I cannot find a clear example how to implement a parallax effect on images as yo

2条回答
  •  执笔经年
    2020-12-13 04:01

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

提交回复
热议问题