YouSub
Untitled

en English

Untitled English subtitles

0 downloads · 84 lines · added Nov 7, 2015

Report a problem
What's wrong?
Advertisement

English transcript

Okay, so we saw how this linear layout contains two
children text views inside it.
By the way, these background colors are just a teaching tool to help you
understand that these two children text views are inside this parent.
The red and blue colors actually won't show up on the device
unless you specifically set them as background colors on these views.
To show you what I mean let's go to the XML Visualizer.
If we drop in the code to the XML Visualizer,
this is what it looks like on the device.
So first we have a LinearLayout viewgroup, and
this is transparent because there's no background color set on it.
The first child is a TextView that sets guest list, so
that shows up at the top here.
The second child is a TextView that says Kunal and
that shows up below the first TextView.
Now, if I copy this TextView and paste it below this one,
what do you think will happen?
Yup, we have another Kunal that shows out right below the first one.
Okay, so the pattern seems to be if we add more TextViews,
here, then they'll just show up one after the other in this list.
Now let's look at the code more closely.
It starts with an opening angle bracket and
then the view name, which is LinearLayout.
Then it lists a bunch of attributes and then there's a closing angle bracket.
Notice that there's no forward slash because this is just the opening
tag of the LinearLayout.
The closing tag is all the way down here, because we
want to insert children elements in between the opening and the closing tag.
But for example, for this test view, since there are no children within that,
then we can just use a self closing tag for it.
Same for this text view here, and this text view here.
So when we say a view group contains children views,
then we need to inset them in between the opening and closing tags.
Now, the other thing you may have noticed is this attribute called Android
orientation equals vertical.
We haven't seen this before, so
let's look at the Android documentation like I showed you earlier.
I open up a new browser window, and then I type in android orientation.
The first result is about a LinearLayout, and
it's on the developer.android.com site.
So let's click on it.
Just like the textview documentation, it was a little overwhelming.
We can ignore most of this text.
We just need to verify that this indeed is the page for LinearLayout, and
then we scroll down and look at the XML attributes.
Now, we're looking for the attribute that is called Android orientation, and
here it is.
So let's click on it to look at more details.
The description says that this attribute
determines whether the layout should be a column or a row.
The value of this attribute should be horizontal for
a row, where the value should be vertical for a column.
And then it lists those two values here.
Cool, so our code currently says that the android orientation is vertical.
So that explains why the views are showing up as a column.
Now, to satisfy our curiosity, we should also try the other value.
Let's set the orientation to be horizontal and see what happens.
I'm going to go into the code and erase the vertical value.
I'm going to type horizontal, and look, now the views are in a horizontal row.
I don't know about you, but
I don't really like to read my guest list horizontally.
But there are still many other useful
cases where you would want a horizontal linear layout.
For example, if you're creating a list item, you might want an image on
the left hand side, and then a description on the right hand side.
I'm going to let you try this out on your own in a second, but
first I want to point out this additional line of code.
This is the XML namespace declaration.
We use this namespace in order to specify that all of these attributes
here belong to android.
That's why they all start with android colon.
This is essentially short hand for this specific URL that's unique to android.
You can actually create your own custom attributes.
So to prevent name conflicts, where two attributes are named the same thing,
but actually have different behaviors, we always add this prefix here,
android:, to signify that these are android attributes.
So basically, always remember to add this XML namespace declaration
in the opening tag of the root view of your XML file.
Now it's your turn.
We want you to be able to experiment with the linear layout code now.
Try to add more TextViews so there's more items in this column.
Who would you put on an exclusive guest list for your party?
Also try changing the linear layout orientation attribute.
Remember that it can be set to vertical or horizontal.

Need subtitles from another video?