Azoft / CarouselLayoutManager

Android Carousel LayoutManager for RecyclerView
Apache License 2.0
2.56k stars 367 forks source link

Reduce Gap issue on Center Scroll Layout Manager. #96

Closed asadmukhtar28 closed 5 years ago

asadmukhtar28 commented 5 years ago

I want to reduce the gap size b/w items using center scroll layout manager because of that i have only 5 items in recyclerview and first one and the last one is just empty view. I also want that recyclerview not move to the empty views.

asadmukhtar28 commented 5 years ago

I have solved my problem while implementing this part of the code.I also write a wrapper on top of CarouselLayoutManager for simplifying my solution to this problem.

layoutManager.setPostLayoutListener(new PostLayoutListener() {

            @Override
            public ItemTransformation transformChild(@NonNull final View child, @NonNull final RecyclerView.ViewHolder currentItem,
                                                     @NonNull final RecyclerView.ViewHolder previousItem,
                                                     final LayoutOrder layoutOrder, final int orientation) {
                // because scaling will make view smaller in its center, then we should move this item to the top or bottom to make it visible
                float translateX;
                float itemPositionToCenterDiff = layoutOrder.mItemPositionDiff;

                translateX = child.getWidth() * itemPositionToCenterDiff * .1f;

                return new ItemTransformation(1.0f, 1.0f, translateX, 0.0f);

            }
        });