Scrolling Parallax Header in RecyclerView with Multiple View Types

The name pretty much explains my need. I have an RecyclerViewadapter with N number of views. I tried 3 different third-party libraries (e.g. https://github.com/kanytu/android-parallax-recyclerview ) that should support the parallax header view. None of them seem to work or need a custom adapter that does not apply to my use case. Perhaps they play internally with view types.

Is there a library that will support several types of views in the scroll header of the adapter and parallax?

Thanks.

+4
source share
1 answer

ItemDecoration . , .

public class ParallaxHeaderDecoration extends RecyclerView.ItemDecoration {

    private Bitmap mImage;

    public ParallaxHeaderDecoration(final Context context, @DrawableRes int resId) {
        mImage = BitmapFactory.decodeResource(context.getResources(), resId);
    }

    @Override
    public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
        super.onDraw(c, parent, state);
        for (int i = 0; i < parent.getChildCount(); i++) {
            View view = parent.getChildAt(i);
            if (parent.getChildAdapterPosition(view) == 20) {
                int offset = view.getTop() / 3;
                c.drawBitmap(mImage, new Rect(0, offset, mImage.getWidth(), view.getHeight() + offset),
                        new Rect(view.getLeft(), view.getTop(), view.getRight(), view.getBottom()), null);
            }
        }

    }
}

bg .

RecyclerView with parallax backgrounds

https://github.com/bleeding182/recyclerviewItemDecorations

+2

Source: https://habr.com/ru/post/1612954/


All Articles