LayoutManager for RecycleView for what?


LayoutManager for RecycleView for what?



I can not find an explanations why we need to set LayoutManager for RecycleView.
Someone can explain ?


LayoutManager


RecycleView


mLayoutManager = new LinearLayoutManager(this);
mRecyclerView.setLayoutManager(mLayoutManager);





Actually have you read about LayoutManager? if no please read here
– Sree...
Jun 29 at 10:52





Please read about Layout manager over here
– Wizard
Jun 29 at 10:52





developer.android.com/reference/android/support/v7/widget/…
– Nilesh Rathod
Jun 29 at 10:53




4 Answers
4



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


RecyclerView


GridLayoutManager





He is not asking what LinearLayoutManager is for, but layout managers in general. Your answer does not answer this. Please update it
– Tim Castelijns
Jun 29 at 12:45





@TimCastelijns please read question properly sir.. he is asked why we need to set LayoutManager for RecycleView...i answered correctly...if you want add some point please edit my answer or give new answer as you own...
– Gowthaman M
Jun 29 at 12:49



LayoutManager


RecycleView





you did not answer correctly. You answered in the context of LinearLayoutManager only
– Tim Castelijns
Jun 29 at 12:54





@TimCastelijns please check my answer carefully i already given offical doc also....i hope this is enoungh.
– Gowthaman M
Jun 29 at 13:58






yes you gave a link, but only a link for LinearLayoutManager. Your answer is extremely minimal, does not answer the question "why do we need to set layout managers" and explains nothing about GridLayoutManager besides mentioning that it exists, so no, your answer is not enough. Just because 3 people upvote your answer does not mean it is automatically a good answer
– Tim Castelijns
Jun 29 at 14:11




The layout manager takes responsibility for positioning your items in the view. It calculates the size and position of each item.



One of the best examples of using LayoutManager is to create a horizontal RecycleView


RecycleView


LinearLayoutManager layoutManager = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);

RecyclerView myList = (RecyclerView) findViewById(R.id.my_recycler_view);
myList.setLayoutManager(layoutManager);



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().






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Comments

Popular posts from this blog

paramiko-expect timeout is happening after executing the command

how to run turtle graphics in Colaboratory

Export result set on Dbeaver to CSV