English subtitles

← 3 - Minor Adjustments SOL

Get Embed Code
13 Languages

Showing Revision 3 created 05/24/2016 by Udacity Robot.

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