androidmanifest
androidmanifest

Reputation: 289

LayoutManager for RecycleView for what?

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

Answers (4)

Kamlesh
Kamlesh

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

Gowthaman M
Gowthaman M

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 the GridLayoutManager as well

Upvotes: 2

xPain
xPain

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

uprightbassfan78
uprightbassfan78

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

Related Questions