Advertisement
English transcript
Remember the coffee bean trail, Katherine?
>> How can I forget?
>> I know. >> You spilled it all over me.
[LAUGH] >> [LAUGH] So
we talked about how there would be three big parts to Lesson one.
>> Mm-hm. >> And we spoke about image and
TextView.
And then we learned how to style those views.
>> Yes. >> Where are we going next?
>> Well, I was thinking.
Since we only have one view on the screen right now.
>> Yeah.
>> It's a little boring, so we should add more than one view.
>> Right.
And if you think about it, all of the fun apps that we use,
YouTube, OkCupid, what's another one that comes to mind?
>> Gmail. >> Gmail,
they all seem to have more than one views packed in
very neatly on the screen together.
>> Yeah. And the way they do
that is through view groups.
>> Mm-hm.
>> So we'll learn about that next.
And that gives us the power to also position views on the screen
where we want them.
>> Right.
So lets talk about view groups next.
>> So far we've only had a single TextView or
a single ImageView on screen.
If we want to add another view below it we could try to just copy this and
paste it below it.
But then we get an error.
It says the XML document has more than one root view.
There can only be one root view, and it should enclose all of your other views.
If we want both of these TextViews to appear on screen and
not be lonely anymore, then we need to put them in a View Group.
The View Group will then be the single root view for the layout.
View Groups are also views and they are rectangles on the screen.
For example the red and orange rectangles here are all View Groups.
They can have a width, a height or a background color, or other attributes.
Background color here is orange.
Orange. But it could also be transparent so
the View Group isn't even visible to the user.
Instead of holding some content like text for TextView or an image for
an ImageView, the content that a View Group holds is other views.
You can think of a view group as being a container for views.
When a view contains other views, we call it the parent of these views.
So this is the parent.
This is the parent.
And this is the parent.
When a view is inside of a View Group, we call it the child of that View Group.
So this is a child, and this is a child, and this is a child.
Same here, there are two children here, and two children here.
Continuing with the family language, if there are multiple children,
then each of those children are siblings to each other.
These are sibling views, and these are sibling views.
Okay, that was a lot.
To help you remember all the terminology around parent and child and view and
View Group, I want you to meet a very nice family called the Views.
You've already met Tommy TextView.
He's pretty great at displaying text.
You also know his sister, Ivy ImageView, who displayed very beautiful images.
And now we're meeting their parents.
It's always nerve racking to meet the parents.
So we have Laura the LinearLayout and Ray the RelativeLayout.
These are both View Groups,
which we mentioned before are called Parent Views.
Then the Children Views are positioned based on their parent.
Let's look at an example of one parent.
A parent may tell their child to sit or
stand in a specific place and not to move.
Let's ignore the possibility that the child might want to get up
and run around.
Because that's just an edge case.
On a device this means that a parent has control over where to position
its children.
For example, one child Text View can be at the top of the screen and
then a second child ImageView can be below that.
Or, if the parent wishes,
they can rearrange the children in a different way.
The child ImageView can be on the left, and
then the child TextView can be on the right.
We're going to talk about view groups in more detail in this lesson, but
to make sure that you've understood what we've covered so
far, please answer these questions.
For the screenshot on this device, can you tell me how many views there are?
Number 2. For the mountain image, is it a child or
a parent of the red view group.
Number 3, is the red view group a child or a parent of the hiking text view.
Number 4, which of these views are siblings of each other.
And you can just list them here.
>> How can I forget?
>> I know. >> You spilled it all over me.
[LAUGH] >> [LAUGH] So
we talked about how there would be three big parts to Lesson one.
>> Mm-hm. >> And we spoke about image and
TextView.
And then we learned how to style those views.
>> Yes. >> Where are we going next?
>> Well, I was thinking.
Since we only have one view on the screen right now.
>> Yeah.
>> It's a little boring, so we should add more than one view.
>> Right.
And if you think about it, all of the fun apps that we use,
YouTube, OkCupid, what's another one that comes to mind?
>> Gmail. >> Gmail,
they all seem to have more than one views packed in
very neatly on the screen together.
>> Yeah. And the way they do
that is through view groups.
>> Mm-hm.
>> So we'll learn about that next.
And that gives us the power to also position views on the screen
where we want them.
>> Right.
So lets talk about view groups next.
>> So far we've only had a single TextView or
a single ImageView on screen.
If we want to add another view below it we could try to just copy this and
paste it below it.
But then we get an error.
It says the XML document has more than one root view.
There can only be one root view, and it should enclose all of your other views.
If we want both of these TextViews to appear on screen and
not be lonely anymore, then we need to put them in a View Group.
The View Group will then be the single root view for the layout.
View Groups are also views and they are rectangles on the screen.
For example the red and orange rectangles here are all View Groups.
They can have a width, a height or a background color, or other attributes.
Background color here is orange.
Orange. But it could also be transparent so
the View Group isn't even visible to the user.
Instead of holding some content like text for TextView or an image for
an ImageView, the content that a View Group holds is other views.
You can think of a view group as being a container for views.
When a view contains other views, we call it the parent of these views.
So this is the parent.
This is the parent.
And this is the parent.
When a view is inside of a View Group, we call it the child of that View Group.
So this is a child, and this is a child, and this is a child.
Same here, there are two children here, and two children here.
Continuing with the family language, if there are multiple children,
then each of those children are siblings to each other.
These are sibling views, and these are sibling views.
Okay, that was a lot.
To help you remember all the terminology around parent and child and view and
View Group, I want you to meet a very nice family called the Views.
You've already met Tommy TextView.
He's pretty great at displaying text.
You also know his sister, Ivy ImageView, who displayed very beautiful images.
And now we're meeting their parents.
It's always nerve racking to meet the parents.
So we have Laura the LinearLayout and Ray the RelativeLayout.
These are both View Groups,
which we mentioned before are called Parent Views.
Then the Children Views are positioned based on their parent.
Let's look at an example of one parent.
A parent may tell their child to sit or
stand in a specific place and not to move.
Let's ignore the possibility that the child might want to get up
and run around.
Because that's just an edge case.
On a device this means that a parent has control over where to position
its children.
For example, one child Text View can be at the top of the screen and
then a second child ImageView can be below that.
Or, if the parent wishes,
they can rearrange the children in a different way.
The child ImageView can be on the left, and
then the child TextView can be on the right.
We're going to talk about view groups in more detail in this lesson, but
to make sure that you've understood what we've covered so
far, please answer these questions.
For the screenshot on this device, can you tell me how many views there are?
Number 2. For the mountain image, is it a child or
a parent of the red view group.
Number 3, is the red view group a child or a parent of the hiking text view.
Number 4, which of these views are siblings of each other.
And you can just list them here.