RecyclerView vs. ListView

前端 未结 16 1718
名媛妹妹
名媛妹妹 2020-11-22 06:07

From android developer (Creating Lists and Cards):

The RecyclerView widget is a more advanced and flexible version of ListView.

<
相关标签:
16条回答
  • 2020-11-22 06:10

    For list views to have good performance you'll need to implement the holder pattern, and that's easy to mess up especially when you want to populate the list with several different kinds of views.

    The RecyclerView bakes this pattern in, making it more difficult to mess up. It's also more flexible, making it easier to handle different layouts, that aren't straight linear, like a grid.

    0 讨论(0)
  • 2020-11-22 06:11

    The RecyclerView is a new ViewGroup that is prepared to render any adapter-based view in a similar way. It is supossed to be the successor of ListView and GridView, and it can be found in the latest support-v7 version. The RecyclerView has been developed with extensibility in mind, so it is possible to create any kind of layout you can think of, but not without a little pain-in-the-ass dose.

    Answer taken from Antonio leiva

     compile 'com.android.support:recyclerview-v7:27.0.0'
    

    RecyclerView is indeed a powerful view than ListView . For more details you can visit This page.

    0 讨论(0)
  • 2020-11-22 06:12

    RecyclerView was created as a ListView improvement, so yes, you can create an attached list with ListView control, but using RecyclerView is easier as it:

    1. Reuses cells while scrolling up/down - this is possible with implementing View Holder in the ListView adapter, but it was an optional thing, while in the RecycleView it's the default way of writing adapter.

    2. Decouples list from its container - so you can put list items easily at run time in the different containers (linearLayout, gridLayout) with setting LayoutManager.

    Example:

    mRecyclerView = (RecyclerView) findViewById(R.id.my_recycler_view);
    mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
    //or
    mRecyclerView.setLayoutManager(new GridLayoutManager(this, 2));
    
    1. Animates common list actions - Animations are decoupled and delegated to ItemAnimator.

    There is more about RecyclerView, but I think these points are the main ones.

    So, to conclude, RecyclerView is a more flexible control for handling "list data" that follows patterns of delegation of concerns and leaves for itself only one task - recycling items.

    0 讨论(0)
  • 2020-11-22 06:12

    There are many differences between ListView and RecyclerView, but you should be aware of the following in particular:

    • The ViewHolder pattern is entirely optional in ListView, but it’s baked into RecyclerView.
    • ListView only supports vertical scrolling, but RecyclerView isn’t limited to vertically scrolling lists.
    0 讨论(0)
  • 2020-11-22 06:15

    I think the main and biggest difference they have is that ListView looks for the position of the item while creating or putting it, on the other hand RecyclerView looks for the type of the item. if there is another item created with the same type RecyclerView does not create it again. It asks first adapter and then asks to recycledpool, if recycled pool says "yeah I've created a type similar to it", then RecyclerView doesn't try to create same type. ListView doesn't have a this kind of pooling mechanism.

    0 讨论(0)
  • 2020-11-22 06:15

    RecyclerView info

    The RecyclerView was introduced with Android 5.0 (Lollipop). it is included in the Support Library. Thus, it is compatible with Android API Level 7.

    Similarly to the ListView, RecyclerView’s main idea is to provide listing functionality in a performance friendly manner. The ‘Recycler’ part of this view’s name is not there by coincidence. The RecyclerView can actually recycle the items with which it’s currently working. The recycling process is done thanks to a pattern called View Holder.

    Pros & Cons of RecyclerView

    Pros:

    • integrated animations for adding, updating and removing items
    • enforces the recycling of views by using the ViewHolder pattern
    • supports both grids and lists
    • supports vertical and horizontal scrolling
    • can be used together with DiffUtil

    Cons:

    • adds complexity
    • no OnItemClickListener

    ListView info

    The ListView has been around since the very beginning of Android. It was available even in API Level 1 and it has the same purpose as the RecyclerView.

    The usage of the ListView is actually really simple. In this aspect, it’s not like its successor. The learning curve is smoother than the one for the RecyclerView. Thus, it is easier to grasp. We don’t have to deal with things like the LayoutManager, ItemAnimator or DiffUtil.

    Pros & Cons of ListView

    Pros:

    • simple usage
    • default adapters
    • available OnItemClickListener
    • it’s the foundation of the ExpandableListView

    Cons:

    • doesn’t embrace the usage of the ViewHolder pattern
    0 讨论(0)
提交回复
热议问题