private void onCourseListScrollChanged(int scrollY) {
    if (onScroll != null) {
      onScroll.handle(courseList, scrollY);
    }

    // Animate tab elevation depending on the scroll distance.
    float maxElevation = ViewUtils.dpToPx(this, TAB_SCROLL_ELEVATION);
    float elevationDistance = ViewUtils.dpToPx(this, TAB_SCROLL_ELEVATION_DISTANCE);
    float elevationAmount = Math.min(elevationDistance, scrollY) / elevationDistance;
    float elevation = maxElevation * elevationAmount;
    tabs.setElevation(elevation);
  }
Exemplo n.º 2
0
  @TargetApi(Build.VERSION_CODES.LOLLIPOP)
  private void setMaterialLayout(View addButton) {
    addButton.setOutlineProvider(
        new ViewOutlineProvider() {
          @TargetApi(Build.VERSION_CODES.LOLLIPOP)
          @Override
          public void getOutline(View view, Outline outline) {
            int diameter = getResources().getDimensionPixelSize(R.dimen.button_diameter);
            outline.setOval(0, 0, diameter, diameter);
          }
        });
    addButton.setClipToOutline(true);

    addButton.setElevation(getResources().getDimension(R.dimen.elevation_low));

    // Dynamic add state list animator
    Animator press_animator =
        ObjectAnimator.ofFloat(
            addButton,
            "translationZ",
            getResources().getDimension(R.dimen.elevation_low),
            getResources().getDimension(R.dimen.elevation_high));
    press_animator.setDuration(getResources().getInteger(android.R.integer.config_shortAnimTime));

    Animator normal_animator =
        ObjectAnimator.ofFloat(
            addButton,
            "translationZ",
            getResources().getDimension(R.dimen.elevation_high),
            getResources().getDimension(R.dimen.elevation_low));
    normal_animator.setDuration(getResources().getInteger(android.R.integer.config_shortAnimTime));

    StateListAnimator animatorList = new StateListAnimator();
    animatorList.addState(new int[] {android.R.attr.state_pressed}, press_animator);
    animatorList.addState(new int[] {}, normal_animator);
    addButton.setStateListAnimator(animatorList);

    // Dnyamic setBackgroundResource
    addButton.setBackgroundResource(R.drawable.ripple_oval);
  }
 public static void setElevation(View view, float elevation) {
   if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
     view.setElevation(elevation);
   }
 }
 @TargetApi(Build.VERSION_CODES.LOLLIPOP)
 @Override
 public void setElevation(float elevation) {
   if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) super.setElevation(elevation);
   else if (mBackground.setShadow(elevation, elevation)) requestLayout();
 }