Show last item in recycler in center

Viewed 496

I have RecyclerView with 2 columns. What I want is to show last item in center if number of items in list is odd. Something like this

enter image description here

I have tried implementing all the so threads from here https://www.google.com/search?client=firefox-b-d&q=show+last+item+in+recyclerview+center+horizontal+android

I have used below code to set layout manager

    gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
        @Override
        public int getSpanSize(int position) {
            if (mLangInfos.size() % 2 == 0)
                return 1;
            else {
                if (position == mLangInfos.size()-1)
                    return 2;
                else
                    return 1;
            }
        }
    });
    recyclerView.setLayoutManager(gridLayoutManager);

But what this does is it shows last item in full width, see below image.

enter image description here

0 Answers
Related