English subtitles

← Scrolling Along - Solution

Get Embed Code
13 Languages

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

  1. Let's Google search for how to do this.
  2. I'm going to type in how to
    scroll in an android app.
  3. Let's check out the first result.
  4. The question is, how to make
    my layout able to scroll down?
  5. That's pretty similar to what we want.
  6. I skip down to the answer part and
    this has a green check mark and
  7. lots of up votes.
  8. So this could be a good answer.
  9. It says, just wrap all of
    that inside a ScrollView.
  10. And then it has an example, ScrollView,
  11. and then it specifies name space and
    then it says.
  12. Fill_parent for width and height, and
    then it has an ending tag here, and
  13. in this comment it says, put the rest
    of your current view inside of it.
  14. For background knowledge, fill_parent
    is actually the same as match_parent.
  15. It's just an older version of it,
    but they mean the same thing.
  16. On this next line it says that
    ScrollView can contain just one item.
  17. It looks like this was
    someone's original layout, and
  18. then to put inside of
    scroll view then they just
  19. made scroll view be the parent view and
    the linear layout be the child's view.
  20. Okay that was a helpful response so
    let's go back and
  21. see if there's any other solutions.
  22. This person is describing
    the same thing.
  23. They have XML lay out and
    I think they want to make it scroll.
  24. Usually, I don't read
    the full question in detail.
  25. I just get to the answer part.
  26. This person says,
  27. have you tried to include all of
    your XML into a parent ScrollView?
  28. And then they give an example
    of ScrollView, and
  29. then the child is a RelativeLayout.
  30. And then they have a closing tag for
  31. That's all they have in this thread.
  32. But it looks like the two search results
    here gave the same advice of using
  33. a ScrollView.
  34. So let's change our search query
    to search for ScrollView android.
  35. Awesome.
    So it is a view in Android.
  36. And there's a description here.
  37. There's a lot of text here, so
    I'm going to skip reading it, but
  38. if you want to skim it, you can.
  39. Then I'm going to hit Back.
  40. I prefer looking for a code example.
  41. So, the code examples that
    we had earlier were good,
  42. and this one is good as well.
  43. So let's go back to Android Studio.
  44. All of those XML examples
    started with ScrollView.
  45. Immediately there's an error that says
    I don't have the required width and
  46. height of the view.
  47. So, I just added those in and
    specified them to be match_parent.
  48. If I add a closing bracket, then I
    immediately get the closing tag here.
  49. So, I'm going to copy that and
  50. then paste it at the bottom
    of this file down here.
  51. That means the existing linear layout
    is now a child of this ScrollView.
  52. I'm going to select all of this and
    then try to indent it by four spaces, so
  53. it's easier to read as
    a child of this ScrollView.
  54. In Android Studio, if I click on the
    Edit menu, I can go to Indent Selection,
  55. and that will indent it
    over by four spaces.
  56. There.
    Now that looks better.
  57. Oh, but I still have an error here.
  58. It says,
    namespace 'android' is not bound.
  59. I can click for more information.
  60. It says, this inspection checks for
    unbound namespace prefixes in XML.
  61. If you remember way back in lesson one,
  62. I said that Android colon comes
    from this name space right here.
  63. So I think we need to copy this and
    then put it up here.
  64. You should also move
    the tools name space up here.
  65. The tools name space is to provide
    additional attributes that you can add
  66. to your XML to help you debug and
    build your app.
  67. Okay, I'm going to run
    this on my device now.
  68. Okay, there's no visible difference
    to the app because there's not enough
  69. content in the order form to
    make it need to be scrollable.
  70. To really test this,
    I need to add more views to this layout.
  71. I'm going to do same trick as before.
  72. I'm going to copy all these views and
    then paste it into the layout so
  73. that we have a really long order form.
  74. Okay, now the order form is
    really long and it scrolls.
  75. That's exciting.
  76. If I rotate the device,
    then it also scrolls.
  77. Now I can undo those changes and
    go back to our original order form.
  78. I'm still going to leave
    the ScrollView in, though,
  79. because our app will work
    better across all devices.
  80. For users with devices that
    are shorter than this,
  81. they'll still be able to scroll and
    see all the fields.