In my app, I have a horizontal recyclerview with LinearLayoutManager. The recyclerview is surrounded by Relative layout whose width is match_parent. I fetch data from an API and populate the recyclerview. If the API response returns a single data item, I need to show that item in the center of recyclerview. If the API response returns two items, I need to divide the space of the recyclerview equally for the two items. If the API response returns more than two items, the items should have equal gap between each other. Please refer the below screenshot:
I tried with item decoration and custom layout managers, but no use. Suggest a better solution.