Home > OS >  What will be the difference between adding the view programmatically vs using recyclerView?
What will be the difference between adding the view programmatically vs using recyclerView?

Time:12-05

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.

CodePudding user response:

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).

CodePudding user response:

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

  • Related