Return to Video

So Much Real Estate Part 3 (solution)

  • 0:00 - 0:02
    First of all,
    you'll grab the starting code.
  • 0:02 - 0:06
    The next thing you had to do was add
    the library to point to the CardView,
  • 0:06 - 0:10
    which will be nicely inside
    of your greater files for
  • 0:10 - 0:13
    you if you added under project
    structure dependencies.
  • 0:13 - 0:16
    For tablet portrait it was really easy.
  • 0:16 - 0:19
    All you had to do Was replace it with
    currently there in the frame layout with
  • 0:19 - 0:21
    the CardView, and it just worked.
  • 0:21 - 0:24
    You would want to, of course,
    set the card elevation correctly, and
  • 0:24 - 0:26
    say PreventCornerOverlap=False.
  • 0:26 - 0:29
    So that on older devices you didn't
    end up with that little white line.
  • 0:29 - 0:33
    Now for tablet landscape,
    it was slightly more complicated.
  • 0:33 - 0:38
    So you see, what we did is, we actually
    added this CardView aligner here.
  • 0:38 - 0:42
    And we set the marginRight to 64dp, and
  • 0:42 - 0:46
    we set the alignLeft to layout_center,
  • 0:46 - 0:50
    and this allowed us to add
    an additional calculation.
  • 0:50 - 0:52
    But without adding any layout hierarchy,
  • 0:52 - 0:57
    we still were able to add margins
    in this case, which is pretty cool.
  • 0:57 - 1:00
    This allows us to the put the card view
    in the right place on both seven inch
  • 1:00 - 1:03
    and ten inch tablet layouts,
    which is pretty cool.
  • 1:03 - 1:04
    And the other thing we had to do was,
  • 1:04 - 1:07
    of course, replace the frame layout
    that was here with the card view.
  • 1:07 - 1:11
    So that makes sense, so you can see it's
    aligned with the card view aligner, and
  • 1:11 - 1:15
    of course it has card elevation and
    pard prevent corner over lap false.
  • 1:15 - 1:18
    And of course the one other
    note about all of this is that
  • 1:18 - 1:21
    we needed to do something
    in detail fragment.
  • 1:21 - 1:25
    And so what we're going to do is,
    when we are loading up
  • 1:25 - 1:28
    instead of setting ourselves to be
    INVISIBLE like we did before, we're
  • 1:28 - 1:32
    actually going to look at our parent and
    see oh, is our parent a CardView?
  • 1:32 - 1:36
    If so, let's set that to
    being INVISIBLE instead.
  • 1:36 - 1:38
    In onLoadFinished we're
    going to do the same thing.
  • 1:38 - 1:42
    We're going to say oh If
    the parent of us is a card view,
  • 1:42 - 1:44
    then let's set that to be visible.
  • 1:44 - 1:47
    And that'll keep the same behavior
    of when the fragment isn't loaded,
  • 1:47 - 1:48
    we don't see anything.
  • 1:48 - 1:52
    Which is important especially
    in the case of empty view.
  • 1:52 - 1:56
    Now we really don't want to see
    that kind of artifact going on.
  • 1:56 - 1:57
    And so that's it.
  • 1:57 - 1:59
    Pretty straight forward.
  • 1:59 - 2:03
    That one little challenge I think with
    the space in the relative layout, but
  • 2:03 - 2:09
    it's a good example of how one can use
    another view to do arithmetic for you.
  • 2:09 - 2:11
    And sometimes you have to
    do that in Android views.
タイトル:
So Much Real Estate Part 3 (solution)
概説:

more » « less
Video Language:
English
Team:
Udacity
プロジェクト:
UD855 - Android Fundamentals 2
Duration:
02:11

English subtitles

改訂 Compare revisions