0

There is a canvas and As a beginner, I have learned about viewGroup in android and how to add a view or multiple views in a viewGroup using either xml or programmatically using addView. We can add as many view we want to add and we can also increase the height of the view dynamically using layoutParams. While we can use addView or setLayoutParams to increase the height of the canvas as we add more pages, why should we use recyclerView?

From the UI perspective, everything seems equal here whether we say increasing height or adding view or list of items. Even though when we are increasing the height, there is a separator between each addition. However, the separator is not a major concern here. Basically, based on numbers of pages or items or data, we are increasing the height of the canvas view so that we can include and show all the data. These numbers of pages has been set to 14 currently but it can be increased without any limit and each canvas board can contain an unpredictable amount of data - may be hundreds of dots, a combination of lines, shapes, text, images and so on - which is fair. We are not limiting user to draw only certain amount of things on individual canvas board.

E_net4
  • 27,810
  • 13
  • 101
  • 139
Sagar Patel
  • 506
  • 1
  • 8
  • 23

2 Answers2

1

RecyclerView is a powerful tool to efficiently display large sets of data with so many abilities such as caching and show items with animation. Using RecylcedrThere is nothing to compare between RecyclerView and addView() cause their usage is different. However i recommend you to read this article about how does RecyclerView Works.

How Does RecyclerView Works

Ali Babadi
  • 114
  • 9
  • Thanks @Ali Babadi for taking time to help. I have gone through the official documentation of the recyclerView [Here](https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.Adapter) and under [onCreateViewHolder](https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.Adapter#onCreateViewHolder(android.view.ViewGroup,%20int)) section, I found this line: ```ViewGroup: The ViewGroup into which the new View will be added after it is bound to an adapter position.``` I understand, ```recyclerView``` is also using ```addView``` only. – Sagar Patel Dec 04 '21 at 07:49
  • If ```recyclerView``` is also using ```addView```, where are the difference and optimization? – Sagar Patel Dec 04 '21 at 07:50
  • 1
    `RecyclerView` uses cache strategy to retrieve the cached view from RecycledViewPool. – Ali Babadi Dec 04 '21 at 08:18
1

While we can use addView or setLayoutParams to increase the height of the canvas as we add more pages, why should we use recyclerView?

Because RecyclerView is more efficient for large sets of data.

From the UI perspective, everything seems equal here whether we say increasing height or adding view or list of items.

No, it's not. If you add a 1000 items to a ViewGroup it will try to draw 1000 items, dragging your app to a crawl at best, or crashing at worst.

If you add 1000 items to a RecyclerView it will draw however many will fit on screen.

These numbers of pages has been set to 14 currently but it can be increased without any limit

Untrue. There is always a limit. It maybe large, but there are always limits. In this case, the limits are on RAM (how much data can the device hold in memory before it craps out).

dominicoder
  • 9,338
  • 1
  • 26
  • 32