Advertisement
English transcript
We've been making a guest list so far for the party.
>> Wait, this is the guest list for the birthday party, right, Catherine?
>> Yeah.
>> I really hope I'm on this list.
>> Well, we'll have to see about that.
>> Wow, I feel really small about that.
>> Well, speaking about small,
let's talk about the size of views on a screen.
>> Oh, we've used the fixed written height, which is the dp, right?
>> Yeah, the width and height.
And we could also set, wrap content, with view.
>> Right, which is a strange way of saying that the view is going to
wrap itself around the content.
So the content grows large,
the view grows large, the content is small and the view grows small.
>> Yeah, and there's actually a third one which is called, match parent.
>> That seems a little strange.
That sounds like a dating website for single parents.
>> Not quite.
Match parent means that the view will be As wide or as tall as the parent.
>> Oh, so that makes sense.
I am a view, I have a parent and my width and
height is going to be the same as my parent.
Okay. >> Exactly, so that's to summarize,
the different values that you can set for a size of a view is width.
Fixed dp for width and height.
>> Correct, you can also do wrap_content.
And the next one we're going to try out is
>> match_parent.
Here are some examples of how setting different widths on the child views
in a linear layout can affect the final user interface.
In this example we set each child view to have a fixed width of 200 dp.
If the content inside each view is greater than 200 DP
then you run risk of cutting some content off like this.
In this example we set each child view to have a width a wrap content.
Now all the content content is shown, but
the width of each view really varies based on what's inside each view.
In this example, we set the width of each child view to be match parent.
Now you see that the width of each child is as wide as the parent view group.
Regardless of the content inside of it.
Now those same values can also be applied for the height of each view.
In this example we set the height of this child text view to be 200 dp.
If the content inside it is taller than that.
Then you run the risk of cutting off some of the content.
In this example, we set the height of the child text view to be wrap content.
That way all the content will be displayed on screen and
nothing will be cut off because the size of the text view is dependent
on the content inside of it.
In this example, we set the height of the child text view to be match parent.
That way the child view is as tall as the parent itself,
regardless of the content inside it.
Let's open the XML visualizer now and
try to be more like our parents in the code.
We're providing you a link to the XML visualizer with some starter code
in the instructor notes below.
In this case, the LinearLayout is the root view
of this layout because it's the first and outermost view.
If we set match_parent for the width and height of this root view, and
we set this as the main layout of our app,
then this linear layout will be as tall and wide as the device screen.
I can show you by setting the background of this linear layout
to be a non-transparent color.
If I set a gray background color on this linear layout Then,
you can see how the gray extends the full width and height of the device.
Now, what happens if I try to change the width or
height of these text views to be match parent?
To make it clear where the bounds of each view are,
I'm going to set a background color on each of the views.
Now I'm going to change the height of this text view to be match parent.
By the way, you spell it match_parent.
And now you see that this text view takes up the full height of the parent.
Unfortunately, it pushes everything else off the screen, so
we don't really want that.
So let's change it back to wrap content.
Okay.
So let's change the width now to be match parent and see what it does.
Now the width of the TextView is as wide as the parent, which in turn,
is as wide as the device screen.
If I change the other TextViews to also be match_parent
You can see that it also starts to take up the full width of the parent.
I also want to point out one more thing.
Every time you see an attribute that starts with layout underscore, like
layout height or layout width, these are actually view group layout parameters.
These are used by the parent view group to determine the size and
the position of these views.
Meanwhile, the other attributes like background, text size, and
text are handled by the TextView in terms of styling its own view.
But these view group layout parameters are handled by the parent.
Now it's your turn to try different width and height values.
For the link to the XML visualizer with some starter code,
see the instructor notes below.
Try to change the width and height values of each TextView.
You can set a fixed dp value, wrap-content, or match_parent.
Remember that for each view, the width and height values don't have to match.
When you're done, check this box to continue.
>> Wait, this is the guest list for the birthday party, right, Catherine?
>> Yeah.
>> I really hope I'm on this list.
>> Well, we'll have to see about that.
>> Wow, I feel really small about that.
>> Well, speaking about small,
let's talk about the size of views on a screen.
>> Oh, we've used the fixed written height, which is the dp, right?
>> Yeah, the width and height.
And we could also set, wrap content, with view.
>> Right, which is a strange way of saying that the view is going to
wrap itself around the content.
So the content grows large,
the view grows large, the content is small and the view grows small.
>> Yeah, and there's actually a third one which is called, match parent.
>> That seems a little strange.
That sounds like a dating website for single parents.
>> Not quite.
Match parent means that the view will be As wide or as tall as the parent.
>> Oh, so that makes sense.
I am a view, I have a parent and my width and
height is going to be the same as my parent.
Okay. >> Exactly, so that's to summarize,
the different values that you can set for a size of a view is width.
Fixed dp for width and height.
>> Correct, you can also do wrap_content.
And the next one we're going to try out is
>> match_parent.
Here are some examples of how setting different widths on the child views
in a linear layout can affect the final user interface.
In this example we set each child view to have a fixed width of 200 dp.
If the content inside each view is greater than 200 DP
then you run risk of cutting some content off like this.
In this example we set each child view to have a width a wrap content.
Now all the content content is shown, but
the width of each view really varies based on what's inside each view.
In this example, we set the width of each child view to be match parent.
Now you see that the width of each child is as wide as the parent view group.
Regardless of the content inside of it.
Now those same values can also be applied for the height of each view.
In this example we set the height of this child text view to be 200 dp.
If the content inside it is taller than that.
Then you run the risk of cutting off some of the content.
In this example, we set the height of the child text view to be wrap content.
That way all the content will be displayed on screen and
nothing will be cut off because the size of the text view is dependent
on the content inside of it.
In this example, we set the height of the child text view to be match parent.
That way the child view is as tall as the parent itself,
regardless of the content inside it.
Let's open the XML visualizer now and
try to be more like our parents in the code.
We're providing you a link to the XML visualizer with some starter code
in the instructor notes below.
In this case, the LinearLayout is the root view
of this layout because it's the first and outermost view.
If we set match_parent for the width and height of this root view, and
we set this as the main layout of our app,
then this linear layout will be as tall and wide as the device screen.
I can show you by setting the background of this linear layout
to be a non-transparent color.
If I set a gray background color on this linear layout Then,
you can see how the gray extends the full width and height of the device.
Now, what happens if I try to change the width or
height of these text views to be match parent?
To make it clear where the bounds of each view are,
I'm going to set a background color on each of the views.
Now I'm going to change the height of this text view to be match parent.
By the way, you spell it match_parent.
And now you see that this text view takes up the full height of the parent.
Unfortunately, it pushes everything else off the screen, so
we don't really want that.
So let's change it back to wrap content.
Okay.
So let's change the width now to be match parent and see what it does.
Now the width of the TextView is as wide as the parent, which in turn,
is as wide as the device screen.
If I change the other TextViews to also be match_parent
You can see that it also starts to take up the full width of the parent.
I also want to point out one more thing.
Every time you see an attribute that starts with layout underscore, like
layout height or layout width, these are actually view group layout parameters.
These are used by the parent view group to determine the size and
the position of these views.
Meanwhile, the other attributes like background, text size, and
text are handled by the TextView in terms of styling its own view.
But these view group layout parameters are handled by the parent.
Now it's your turn to try different width and height values.
For the link to the XML visualizer with some starter code,
see the instructor notes below.
Try to change the width and height values of each TextView.
You can set a fixed dp value, wrap-content, or match_parent.
Remember that for each view, the width and height values don't have to match.
When you're done, check this box to continue.