Return to Video

3 - Minor Adjustments SOL

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

more » « less
Video Language:
English
Team:
Udacity
Project:
UD837 - Android for Beginners
Duration:
02:26

English subtitles

Revisions Compare revisions