YouSub
Untitled

en English

Untitled English subtitles

0 downloads · 50 lines · added Dec 5, 2015

Report a problem
What's wrong?
Advertisement

English transcript

All right, so were actually two correct answers to this question and
they were padding and layout_margin.
So you could have select either one of these but you don't need both.
Let me show you why.
In practice, a lot of times, a view that uses
padding will look very similar to a view that uses layout_margin.
Let me actually draw the view borders for you.
Once you draw the view borders,
you could actually see the difference between these two situations.
In the case of padding,
you're making the actual view larger by adding space inside of The view.
In the case of layout_margin, you're adding space around the view, but
not actually changing the size of the view.
Now, you might be wondering when does this even come into play?
Why have two different attributes?
Well, if I were to do something like add a border or a background
color to both of these views, they'd actually look pretty different.
In our case, though, we're not adding a border or background color, so
you can pick either padding or layout_margin.
It just wouldn't make sense to pick both.
Since we can choose either, I'm going to go ahead and, a bit arbitrarily,
choose to add padding.
Let's see what this would look like in Android Studio.
All right, here we are back in activity_main.
Now the padding attribute is something that we want to add to the TextViews
to move them farther away from the side of the screen.
Padding and layout_margin add space on all four sides.
All right, let's go ahead and add it.
And remember, I said that I wanted there to be 20dp on all sides, so
that's what I'm putting right here as the value.
My preview is updated to show the added space,
I'm going to go ahead and scroll down.
All right, and I'm feeling a little bit playful, so I'm going to go ahead and
add layout_margin to this TextView instead of padding.
All right, and that also scooted the TextView out.
Notice, though,
that the TextView's size didn't increase when I changed the layout_margin,
whereas up here in this TextView, the size of the actual TextView has changed.
Now what happens if I add both layout_margin and padding.
Let's take a look.
Well, now my text is 40dp away from the wall.
It's 20dp here and then another 20dp of padding here.
All right, but we don't want 40dp away from the wall.
So I'm going to go ahead and delete this.
Okay, 20dp of padding in the From, Lyla TextView.
And 20dp of padding and the Happy Birthday, Ben text view.
Awesome, let's run this on our phone.
All right, and may I present to you the finished Birthday Card app.
Let's get some jazz hands.
And with that, we complete the last thing in our to-do list.

Need subtitles from another video?