devunwired / recyclerview-playground

Examples of RecyclerView use and custom LayoutManager implementations
MIT License
1.25k stars 270 forks source link

Multi type item wrong size #30

Closed Jericho2Code closed 7 years ago

Jericho2Code commented 7 years ago

Good day, I try to use FixedGridLayoutManager class in my project, and when I add to recyclerView different items, there are have same height and wight, like in first shown. I think, that problem in this part:

/*
             * We make some assumptions in this code based on every child
             * view being the same size (i.e. a uniform grid). This allows
             * us to compute the following values up front because they
             * won't change.
             */
            mDecoratedChildWidth = getDecoratedMeasuredWidth(scrap);
            mDecoratedChildHeight = getDecoratedMeasuredHeight(scrap);
Jericho2Code commented 7 years ago

Add update the values of variables, and this help:

/*
                 * It is prudent to measure/layout each new view we
                 * receive from the Recycler. We don't have to do
                 * this for views we are just re-arranging.
                 */
                measureChildWithMargins(view, 0, 0);

                mDecoratedChildWidth = getDecoratedMeasuredWidth(view);
                mDecoratedChildHeight = getDecoratedMeasuredHeight(view);

                layoutDecorated(view, leftOffset, topOffset,
                        leftOffset + mDecoratedChildWidth,
                        topOffset + mDecoratedChildHeight);