English subtitles

← Building Todays List Item - Developing Android Apps

Get Embed Code
10 Languages

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

  1. Let me the explain the reasoning
    that I use when I look at a new layout.
  2. It looks like there's two
    equally spaced columns here.
  3. That signals to me, that
    we need LinearLayout weights,
  4. where each of these have equal weights.
  5. So let's create
    a horizontal LinearLayout.
  6. Within this first child, we have
    three vertically stacked text views,
  7. so we have a vertical LinearLayout,
    and the same goes for this second child,
  8. which has two elements vertically
    stacked on top of each other
  9. which means we use
    a vertical LinearLayout as well.
  10. And here's the code, we created a new
    list_item_forecasts_today.xml file
  11. under the layout folder.
  12. The code looks very similar
    to list_item_forecast.
  13. It has a horizontal LinearLayout,
    as a root element.
  14. The first child is a vertical LinearLayout
  15. with width zero and a weight of one.
  16. The second child is another
    vertical LinearLayout
  17. with a width of zero and a weight of one,
  18. that way the horizontal space
    will be distributed evenly
  19. among each child.
  20. If you go back to the first LinearLayout,
  21. notice that we have
    three TextViews within it,
  22. for date, high temperature,
    and low temperature.
  23. We specify gravity
    to be center horizontal,
  24. so anything within the LinearLayout
    will be centered horizontally.
  25. Otherwise, by default, they would be
    left-aligned to the LinearLayout.
  26. The same applies for the
    second LinearLayout.
  27. We specify gravity to be
    center horizontal so that the icon
  28. and the weather forecast TextView
    within it are also centered horizontally.