Return to Video

Change the TextView

  • 0:01 - 0:04
    Okay, so we've seen TextView code for
    the first time.
  • 0:04 - 0:06
    >> But
    it's kind of hanging out in limbo.
  • 0:06 - 0:09
    >> Right, we do need a space
    where we can house it.
  • 0:09 - 0:11
    >> Yeah, that space is an IDE.
  • 0:11 - 0:13
    >> There's that acronym again.
  • 0:13 - 0:14
    What does it stand for again, Catherine?
  • 0:14 - 0:16
    >> Integrated Development Environment
    >> Right, and
  • 0:16 - 0:20
    we are going to be using
    Android Studio in this class.
  • 0:20 - 0:22
    This is what it looks like.
  • 0:22 - 0:23
    Still a little intimidating.
  • 0:23 - 0:25
    >> Yeah.
    I think we might need something
  • 0:25 - 0:28
    that will help our learner
    ramp up a little bit easier.
  • 0:28 - 0:31
    >> Right, so we've been working
    on developing something that is
  • 0:31 - 0:35
    Android Studio on training wheels,
    in the tradition of really convoluted
  • 0:35 - 0:38
    acronyms in computer science,
    we are calling it XMLV.
  • 0:38 - 0:39
    >> Which stands for XML Visualizer.
  • 0:39 - 0:41
    >> So you write a little bit of XML?
  • 0:41 - 0:42
    You get to see the output.
  • 0:42 - 0:45
    You write some more,
    you get to see more output.
  • 0:45 - 0:45
    >> Yeah.
  • 0:45 - 0:46
    So let's go use it.
  • 0:46 - 0:47
    >> Okay.
  • 0:47 - 0:52
    >> Since this XML visualizer was
    created specifically for this course,
  • 0:52 - 0:55
    it won't provide all the functionality
    that Android Studio supports.
  • 0:55 - 0:58
    But eventually in the problem
    set of this lesson,
  • 0:58 - 1:01
    we'll get you into Android Studio so
    you won't need this website anymore.
  • 1:02 - 1:06
    A link is in the instructor notes
    If you want to follow along.
  • 1:06 - 1:08
    For this code,
    the text says Happy Birthday.
  • 1:08 - 1:12
    So when I look at the device it says,
    Happy Birthday.
  • 1:12 - 1:15
    Now let's try to change the text
    to Happy Birthday, Kunal.
  • 1:16 - 1:20
    And then when I zoom in on the device
    preview you see that it now says,
  • 1:20 - 1:21
    Happy Birthday, Kunal.
  • 1:21 - 1:24
    And what happens by trying to
    stand the width and the height.
  • 1:24 - 1:28
    I'll pick some arbitrary
    values like the 300dp for
  • 1:28 - 1:30
    the width and 500 for the height.
  • 1:30 - 1:34
    And now in the preview pane, you see
    that the TextView is a lot bigger.
  • 1:35 - 1:39
    The text though, however, is still
    the same size in the top left corner.
  • 1:41 - 1:44
    Notice that for the width and
    height values of 300 and
  • 1:44 - 1:48
    500 is followed by dp in each case.
  • 1:48 - 1:51
    This is a unit of measure
    like centimeters or
  • 1:51 - 1:55
    millimeters, that we use to describe
    the size of views on Android.
  • 1:55 - 1:57
    As well as the distancing between views.
  • 1:59 - 2:01
    The unit dp stands for
    density-independent pixels.
  • 2:03 - 2:05
    Let me explain why we need that.
  • 2:05 - 2:09
    Say these beautifully drawn rectangles
    represent different devices.
  • 2:09 - 2:14
    They're the same physical size, but
    they differ in terms of resolution.
  • 2:14 - 2:19
    This is a medium resolution device with
    a medium number of pixels on the screen,
  • 2:19 - 2:23
    high resolution and
    extra-high resolution device.
  • 2:23 - 2:27
    When I say pixel, I mean a phone screen
    is made up of many tiny squares,
  • 2:27 - 2:30
    which are pixels, and they light up
    based on what you're looking at.
  • 2:30 - 2:35
    So if I define the size of a view, for
    example, a button, to be 2 pixels tall
  • 2:35 - 2:39
    by 2 pixels wide, this is what it would
    look like on a medium resolution device.
  • 2:40 - 2:43
    On a high resolution device,
    it would also be 2 pixels by 2 pixels.
  • 2:43 - 2:45
    But it's a little bit smaller,
  • 2:45 - 2:49
    because there's a lot more pixels trying
    to be packed into this device, and
  • 2:49 - 2:53
    then on an extra high resolution device
    where there's tons more pixels packed
  • 2:53 - 2:57
    into this space,
    this button is actually pretty tiny.
  • 2:57 - 2:58
    I can barely tap on it with my finger.
  • 2:58 - 3:03
    I have to use edge of my finger or
    my fingernail to reach it.
  • 3:03 - 3:05
    Just because I have extra
    high resolution device,
  • 3:05 - 3:07
    doesn't mean I have a smaller finger.
  • 3:07 - 3:10
    I still want to be able to tap
    the buttons on the screen.
  • 3:10 - 3:13
    And that is why we have
    density-independent pixels.
  • 3:13 - 3:16
    I can define my button to
    be 2dps tall by 2dps wide.
  • 3:16 - 3:19
    This is what it would look like
    across the different devices.
  • 3:19 - 3:22
    It is the same physical size, but
  • 3:22 - 3:26
    under the hood Android is mapping
    it to a different number of pixels.
  • 3:26 - 3:29
    You don't have to worry about any of
    that logic, all you need to remember
  • 3:29 - 3:34
    is that you need to define your
    sizes in terms of dp values.
  • 3:34 - 3:38
    When designing your apps, we recommend
    that all touch targets like buttons
  • 3:38 - 3:41
    should be at least 48dps tall and wide.
  • 3:41 - 3:44
    Notice that it says 48dps and
    not 48 pixels,
  • 3:44 - 3:48
    otherwise it would be really tiny on
    this extra high resolution device.
  • 3:48 - 3:51
    This will make your app easy to use for
    everyone.
  • 3:51 - 3:53
    So with all of this knowledge,
    I want you to try and
  • 3:53 - 3:55
    change the TextView code now.
  • 3:55 - 4:00
    You're going to be writing your very
    first lines of XML, how exciting.
  • 4:00 - 4:03
    So first try to change
    the text in the TextView.
  • 4:03 - 4:05
    And then try to change
    the sides of the TextView.
  • 4:06 - 4:10
    Then I want you to try to
    create an error sad face.
  • 4:10 - 4:12
    And then I want you to undo it,
    happy face.
Title:
Change the TextView
Description:

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

English (United States) subtitles

Revisions Compare revisions