Welcome back in this video, I would like to talk about the recycled view on a theoretical level and
why we use it, because we will use recycled views quite a bit and they are super important pretty much
in any application because they allow us to use lists on and list views and grid views and those kind
of things.
So let's look at it.
First of all, Android used to use the list you and grid view classes for displaying lists a recycler
can be thought of as a combination of a list view and grid you.
So it allows us to do both, however, and recycle you.
There are features that separate your code into maintainable components, even as they enforce memory
efficient design pattern.
So it's a lot more efficient, pretty much.
So it's a better way to create lists than list, view and grid.
You have a work, and why should we use a recycle you?
Well, imagine you're creating a list you with complicated custom items such as, for example, in Facebook,
you have images and then you have text, and then you have the like button amount of likes who posted
it and so forth, all these kind of things.
They are complicated, custom icon items, so to speak, and you create a row layout for the items and
use that layout inside your adapter.
Well, you let your item layout and get view referencing each you with a unique and you provide it in
XML to customize and have your logic.
You parcel to the list view and it's ready to be drawn on the screen.
Well, is it or is it not?
Well, the thing is list use and is only do half the job of achieving true memory efficiency, and that
is something that is super important.
More complicated, your individual list items become, of course, because then there is a lot going
on and there's a lot to load.
And if you have many images that need to be loaded, then well, this whole stuff has to be super efficient.
Otherwise, it feels laggy, especially now with faster and faster screens in terms of the frequency
they display.
For example, with 120 hertz, everything needs to be super fast.
Another reason to use the recycle view is to recycle the item layout, but don't keep references to
the layout children forcing you to call find by view for every child of your item layout.
Every time you call, get a view.
So it's not doing that.
That's what list used it all.
This calling around can become processor intensive, especially for complicated layouts.
And furthermore, the situation can cause your list view scrolling to become jerky and non-responsive
as it tries to grab you references.
So it was fine back in the day, but then things got a lot more complicated.
Of course, devices got faster, but still, why not improve if it's not perfect, right?
So that's what they thought when they created recycled reviews.
Android initially provided a solution to this problem on the Android developer side with smooth scrolling
via the power of the view holder pattern.
And with this pattern, a class becomes an in-memory reference to all the views needed to fill your
layout.
You set the references once and reused them working around the performance head that comes with repeatedly
calling this find if you buy it and find you buy the something that we've never used before because
we just didn't need to do it.
That's the beauty of Scotland.
It just got rid of this whole thing.
You don't need to use it anymore in Java.
It's quite prominent and very important to use it.
But well and cotton, it's less important, and you can even reduce your code to where it's not even
used at all.
So it's pretty cool.
Take note that this is an optional pattern for list your grid view.
If you're unaware of this detail, then you may wonder why your list, view and grid use so slow.
Well, the thing is we never used this because anchorages.
So this is something that doesn't really bother us too much because we will use recycled reviews all
the time.
So we're not even going to start with doing list views and grid views, OK?
We're going to start with recycler use straight away, so it's going to be a lot more efficient from
the start and you will see how to build those things.
All right.
So the arrival of the recycler, you changed everything.
It still uses an adapter to act as a data source.
However, you have to create view holders to keep references in memory.
To provide a new view recycler, you either create a new view holder object to inflate the layout and
hold those references or recycle one from the existing stack.
So why is it called recycle view?
Well, another perk of using recycled views is that they come with default animations that you don't
have to create or add yourself because it requires that you hold it to the right type of, you know,
switch animation to apply to which item and adds them as required.
So you can also create your own animations and apply them as needed.
Now there is something called lay out manager in recycler views, and we're going to actually use that
in order to adjust our recycling elements.
So the list items in our list.
So the last and most interesting component of our recycling view is its layout manager object positions,
the recycle of used items and tells it when to recycle items that have transitioned off screen.
And this is something that list use used to do by themselves back in the day.
So you can imagine that when working with the lists, there are multiple things which are important
to consider.
So one of them is, for example, when you scroll, then you want to see the next list elements directly.
You don't want them to load, you don't want them to take up time in order to load whatever is displayed
in them you want to see directly.
It has to feel smooth and look smooth.
And that is something that is achieved a lot easier with recycled views.
Now another thing is you need, of course, to free up space memory space of elements that are not visible
anymore.
So if a list item is not visible anymore, it's off screen already.
Then at one point you need to release the memory and you shouldn't do that directly.
Maybe the user wants to scroll back.
All right, so maybe you wants to see whatever he's called the way, so it doesn't have to be done directly,
but it's something that recycler views more disrespect of you.
Class and layout matter handle themselves, so it's super powerful.
So the result of you has broken out this functionality to allow for different kinds of layouts, vertical
horizontal grid staggered or a very custom.
So that is the cool thing.
It's super powerful.
You're not limited to grid or list use, but you can really go ahead and build your own layouts, and
they're still going to be efficient because they will still be recycled views, right?
So they'll manager offers free choices by default.
So the linear layout manager positions item to look like a standard list view than the grid layout manager
positions items in a grid format similar to a grid view.
And then we have the staggered grid, a layout manager which positions items in a staggered grid format.
The cool thing is you can, of course, go ahead and create your own layout managers to use with a recycler
view if you want some extra customization.
So these are the basics of recycler views.
And I found this guide here under guides at of corporate slash and slash using the recycled view, which
is pretty cool.
So this guy created a great guide on recycled views, how they work and what you can do with it.
And it's a super extended one.
You can see there are a bunch of sections, so using recycled use, defining a model, modifying the
adapter.
So a lot of stuff, you can see that he even goes to animators.
And so this is an example of what you can do with a staggered grid layout you can see pretty cool.
Of course, it really depends on the images you have and the stuff, but in the end, you can see it's
neither a real grid layout, nor is it a list view.
It's really a staggered grid, so pretty powerful stuff.
And then also, when it comes to animations, as you can see the elements, they get bigger the further
they are in their lower loading process, so to speak.
OK.
So this is just one website.
Of course, there are a bunch of other great to list your other websites.
So this is also, for example, a grid view here that is used in the.
Google Play Store.
OK, so they also used as a affect here, and you can see it can pretty much find anything here.
So I would highly recommend to check that out if you want to know more about this type of use.
Of course, we're going to use recycled of use and we are going to use some of the features that are
explained in here.
But of course, not everything.
So that is something that I in general really encourage you to do.
Each time that we cover something new, that you should also look into other resources to get a bigger
understanding of what because the more different examples you can see, the better your understanding
of something and what a concept will become.
OK, so see you in the next video.