Return to Video

TODO Adding Elevation

  • 0:01 - 0:05
    Right now, we have material sliding
    through material on the same elevation,
  • 0:05 - 0:08
    which is something the spec frowns upon.
  • 0:08 - 0:10
    What we'd like to do is
    something more like this.
  • 0:12 - 0:16
    As you can see, the app bar gains
    in elevation, casts a shadow,
  • 0:16 - 0:18
    when the content slides under.
  • 0:19 - 0:22
    Fortunately, we have a callback for
    when the RecyclerView is scrolling.
  • 0:24 - 0:27
    I just realized there might be a small
    percentage of you that would feel
  • 0:27 - 0:31
    intellectually compromised if you
    didn't get to implement this effect.
  • 0:31 - 0:33
    This is your chance to
    pause the video and
  • 0:33 - 0:35
    attempt to do it yourself
    before I show you the answer.
  • 0:35 - 0:41
    Okay, last chance, and here goes.
  • 0:41 - 0:43
    Here's how I did this.
  • 0:43 - 0:47
    Inside of onCreateView,
    right after our parallax stuff,
  • 0:47 - 0:50
    I checked to see we have an app bar.
  • 0:50 - 0:53
    If we have one,
    I start by setting its elevation to 0.
  • 0:53 - 0:56
    I then I add an OnScrollListener here.
  • 0:56 - 1:00
    And whenever we scroll it we check
    the vertical offset of the RecyclerView.
  • 1:00 - 1:02
    If it's zero then we know
    we're not underscrolled and
  • 1:02 - 1:05
    we set the app bar elevation to zero.
  • 1:05 - 1:08
    Otherwise, we're underscrolled and we
    actually set it to its TargetElevation,
  • 1:08 - 1:10
    which is something that app
    bars do that's kind of cool.
  • 1:12 - 1:15
    And with that,
    we get this nice underscrolling effect.
  • 1:15 - 1:18
    It's a little hard to see
    on the tablet perhaps, but
  • 1:18 - 1:21
    there's actually a little shadow
    there you can see that's being cast.
  • 1:21 - 1:26
    It's a subtle detail, but once again,
    I always say when we're doing these
  • 1:26 - 1:30
    final steps, it's that last 10% that
    really makes an enormous difference.
  • 1:30 - 1:32
    And sometimes, it's the last 1%.
Title:
TODO Adding Elevation
Description:

06-49 Adding Elevation

more » « less
Video Language:
English
Team:
Udacity
Project:
UD855 - Android Fundamentals 2
Duration:
01:33

English subtitles

Revisions Compare revisions