Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I use RecyclerView.VERTICAL instead of LinearLayoutManager.VERTICAL?

Running ./gradlew lint reports me an error which is confusing:

39: Must be one of: RecyclerView.HORIZONTAL, RecyclerView.VERTICAL

In the source code:

    38 LinearLayoutManager linearLayoutManager = new LinearLayoutManager(rootView.getContext());
    39 linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
    40 recyclerView.setLayoutManager(linearLayoutManager);
    41 recyclerView.setAdapter(recyclerAdapter);

Is there any reason I should change 39th line to

linearLayoutManager.setOrientation(RecyclerView.VERTICAL);
like image 965
John Avatar asked Dec 10 '18 05:12

John


People also ask

When should I use RecyclerView?

Use the RecyclerView widget when you have data collections whose elements change at runtime based on user action or network events. If you want to use a RecyclerView , you will need to work with the following: RecyclerView. Adapter - To handle the data collection and bind it to the view.

Which is better ListView or RecyclerView?

Simple answer: You should use RecyclerView in a situation where you want to show a lot of items, and the number of them is dynamic. ListView should only be used when the number of items is always the same and is limited to the screen size.

Can RecyclerView be horizontal?

We can make Horizontal RecyclerView or Horizontal Scrolling in RecyclerView in Android using LinearLayoutManager. If you've used LinearLayout, you might have noticed that you can set the layout orientation to both horizontal and vertical.

What is ViewHolder in RecyclerView Android?

A ViewHolder describes an item view and metadata about its place within the RecyclerView. Adapter implementations should subclass ViewHolder and add fields for caching potentially expensive findViewById results. While LayoutParams belong to the LayoutManager , ViewHolders belong to the adapter.


1 Answers

There is no difference in using the LinearLayoutManager.VERTICAL or RecyclerView.VERTICAL because in LinearLayoutManager they are same.

public class LinearLayoutManager extends RecyclerView.LayoutManager implements
    ItemTouchHelper.ViewDropHandler, RecyclerView.SmoothScroller.ScrollVectorProvider {

private static final String TAG = "LinearLayoutManager";

static final boolean DEBUG = false;

public static final int HORIZONTAL = RecyclerView.HORIZONTAL;

public static final int VERTICAL = RecyclerView.VERTICAL;

As you can see in this code snippet from LinearLayoutManager.

like image 83
Muzammil Husnain Avatar answered Oct 11 '22 11:10

Muzammil Husnain