Welcome back.
In this video, I would like to talk about the recital of you on a theoretical level and why we use
it, because we will use recycled views quite a bit and they are superimportant pretty much in any application
because they allow us to use lists on and list views and views and those kind of things.
So let's look at it.
First of all, Android used to use the list, view and review classes for displaying lists I recycled,
which can be thought of as a combination of a list for you and grade 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 great.
You ever 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 road layout for the items and use that layout inside your adapter.
Well, you inflate your item layout and get view referencing each view with a unique idea you provided
in XML to customize and have your logic.
You add 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 using is only do half the job of achieving true memory efficiency and that
is something that is super important and 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 lagi, 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 recycler 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 view.
So it's not doing that.
That's what list used did all this calling around can become process or intransitive, especially for
complicated layouts.
And furthermore, the situation can cause your list of scrolling to become jerky and nonresponsive as
it tries to grab your 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 the recycler use.
Android initially provided a solution to this problem on the Android developer side with smooth scrolling
via the power of the view.
Hold the pattern.
And with this pattern, it becomes an in-memory reference to all the views needed to fill your layout.
You set the references once and reuse them working around the performance that comes with repeatedly
calling this find view by ID and find Ubaidi is something that we've never used before because we just
didn't need to do it.
That's the beauty of Kotlin.
They 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 Cottan 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 a list for grid view.
If you're unaware of this detail, then you may wonder why your list you introduce so slow.
Well, the thing is, we never used despues anchorages.
So this is something that doesn't really bother us too much because we will use recyclables all the
time.
So we're not even going to start with doing list of using reviews.
OK, we're going to start with recycling 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 recycle, you changed everything.
It still uses an adapter to act as a data source.
However, you have to create value 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 recycles
one from the existing stack.
So why is it called recycle of you?
Well, another perk of using recycled use is that they come with default animations that you don't have
to create or add yourself because it requires a view.
Holder, the recycler view knows which 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 layout manager in of use, and we're going to actually use that in order
to adjust our respective elements so the list items in our list.
So the last and most interesting component of our recital is its layout manager.
The subject positions the recycle of use items and tells it when to recycle items that have transitioned
off screen.
And this is something that Lisieux 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 looks smooth.
And that is something that has achieved a lot easier with a recycler of use.
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 he wants to see whatever he scrolled away so it doesn't have to be done directly.
But it's something that we might have used more disrespect of UCLASS and layout manager 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 grids, staggered or a very custom.
So that is the cool thing and super powerful.
You're not limited to gret or less use, but you can really go ahead and build your own layouts and
they are still going to be efficient because they will still be recycled views.
Right.
So layout manager offers free choices by default.
So the linear layout manager positions item to look like a standard list.
You then the layout manager positions items in a format similar to a great view.
And then we have the staggered grid 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, manages to use with a recycler
view if you want some extra customization.
So these are the basics of recyclable use.
And I found this guy right here under guard, psychopath outcomes, and that's 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 recyclable use, defining a model, modifying the adapter.
So a lot of stuff you can see there, he even goes to animator's.
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 when they're loading process, so to speak.
OK, so this is just one website.
Of course, there are a bunch of other great to list websites.
So this is also, for example, a grid view here that is used in the.
Google Play store.
OK, so they also use this effect here and you can see you can pretty much find anything here.
So I would highly recommend to check that out.
If you want to know more about recyclable use, of course, we're going to use recycled views 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 it, because the
more different examples you can see, the better your understanding of something where a concept will
become.
OK, so see you in the next video.