YouSub
Untitled

en English

Untitled English subtitles

0 downloads · 94 lines · added Dec 12, 2015

Report a problem
What's wrong?
Advertisement

English transcript

First I look at the screen shot and decide that since the,
these are in rows, it looks like a vertical linear layout.
The second child though is not a single view,
in fact that's a horizontal linear layout of three views.
This is what the view hierarchy diagram would look like.
We have a vertical linear layout as a root view and five children under that.
The linear layout itself has three children as well.
Once we have the diagram it's easy to create this skeleton of XML code now.
The root view is a linear layout and
it contains a text view as its first child followed by a linear layout
which has a button, text view, and button inside of it.
And this is the closing tag for the linear layout and
then we have the text view, another text view, and a button.
Which are all children of the parent linear layout.
>From this XML we can go in to Android Studio and
modify our existing layout to look more like this.
In Android Studio I open up activity main XML layout file.
We're going to make the changes in place in this file so
that they match more closely to our desired layout.
The first child is a TextView.
That we already have.
And it's supposed to be the quantity header.
Next we should have a nested linear layout
that contains three views inside of it.
We don't have that yet, so let's add it.
I'm going to hit Enter and then just start typing LinearLayout.
It also shows up as one of the auto complete options.
So I can just hit okay.
Then it auto populates the attributes that I should fill in.
Because width and height are required.
I set the width to be match_parent, which will in turn
match the width of it's parent, and this will match the width of the screen.
For layout height, I don't want to set match_parent, otherwise,
it will push the other views off the screen vertically.
So I'm just going to say wrap_content here.
That way the LinearLayout will only be as tall as the two buttons and
TextView inside of it.
Now, this closing tag should be moved after all the children
of the LinearLayout have been added.
So that will go down here.
When you have children inside of a view group,
you should indent the children by four spaces.
I'm going to add a space here too because I like to have a blank line in
between each XML element.
One more thing we're missing is setting the orientation of this LinearLayout.
Earlier we decided that the LinearLayout should be horizontal so
that the buttons and the TextView appear horizontally.
Cool. Now that matches what we wanted.
Next we have, two TextViews and a Button which we already have in our layout.
So I think we're done.
If you wanted to check the design pane, this is what it would look like.
We have a vertical linear layout with five direct children and
this linear layout has three more children.
Let's run it on our device to see what happens.
So, this looks close to what we want but not quite.
The quantity picker is appearing horizontally, which is a good sign.
But we want the minus button on the left hand side and the plus button
to be on the right hand side, as shown In the screenshot of the desired layout.
Also, these buttons are tightly squeezed up against the edge of this TextView.
If I remember the screenshot correctly, we also want eight dips of space on
the left-hand side and right-hand side of this TextView.
So let's add that now.
Going back to the XML,
I'm going to move the plus button to be after the TextView.
And then move the minus button to be before the TextView.
In a horizontal row, we should have the minus button, followed by the two,
followed by the plus button.
We also want to add padding around this TextView.
We could either add it as margin or padding, but
I'm just going to do padding.
And we'll set the value to be eight dips.
Okay, great.
Now I have a hunch that there's a bunch of extra white spaces and
the ordering of our attributes may be incorrect,
according to the android code style guidelines.
So, in the menu at the top of your screen, click on code and
then click on reformat code.
And also rearrange code.
And that should rearrange all the attributes and
fix up all the formatting for you automatically.
Okay, great.
Let's run the app again.
There. That's better.
Now there's space around the two and the minus button is on the left-hand
side and the plus button is on the right-hand side.
[SOUND] it looks good.
And then we also check that it still works.
So, I'm going to pick an arbitrary quantity and then order.
And that looks correct.
[SOUND] that was a long journey to get this quantity picker on the screen.
All right. The app is looking really good.
But so far, I've only showed you how to show numbers on the screen.
What if you want to show text on the screen?
Keep watching to find out.

Need subtitles from another video?