RecyclerView vs. ListView

前端 未结 16 1929
名媛妹妹
名媛妹妹 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: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

提交回复
热议问题