Reputation: 289
I can not find an explanations why we need to set LayoutManager
for RecycleView
.
Someone can explain ?
mLayoutManager = new LinearLayoutManager(this);
mRecyclerView.setLayoutManager(mLayoutManager);
Upvotes: 1
Views: 179
Reputation: 447
It’s main work is to manage the layout for the large data-set provided by adapter. It positions each item views into it’s appropriate position in the RecycleView. Also, It re-uses the views that are no longer visible to the user. During this, It may ask the adapter to replace the contents of that view with a different element from data-set. Recycling(or Re-using) views in this manners improves performance a lot since there is no need to create extra views and perform costly operations like findViewById().
Upvotes: 1
Reputation: 8282
The LinearLayoutManager allows you to specify an orientation, just like a normal LinearLayout would.
Here is the doc https://developer.android.com/reference/android/support/v7/widget/LinearLayoutManager
Note you can use
RecyclerView
with theGridLayoutManager
as well
Upvotes: 2
Reputation: 144
One of the best examples of using LayoutManager is to create a horizontal RecycleView
LinearLayoutManager layoutManager = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
RecyclerView myList = (RecyclerView) findViewById(R.id.my_recycler_view);
myList.setLayoutManager(layoutManager);
Upvotes: 2
Reputation: 352
The layout manager takes responsibility for positioning your items in the view. It calculates the size and position of each item.
Upvotes: 1