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);
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.
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.
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.
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.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With