How to implement Custom Collapsable Toolbar in android?

前端 未结 1 1906
感动是毒
感动是毒 2021-02-03 16:54

Using this tutorial to implement a Flexible Space pattern (the one with the collapsing toolbar).

I\'m trying to achieve a similar effect as in the

相关标签:
1条回答
  • 2021-02-03 17:05

    The AppBarComponentprovides a method called .setExpanded(boolean expanded), which allows you to expand your AppBarComponent.

    But keep in mind, that this method relies on this layout being a direct child of a CoordinatorLayout.

    You can read this for more information.

    If you want to animate to a custom offset, try using the setTopAndBottomOffset(int) method.

    CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) appBar.getLayoutParams();
    final AppBarLayout.Behavior behavior = (AppBarLayout.Behavior) params.getBehavior();
    if (behavior != null) {
        ValueAnimator valueAnimator = ValueAnimator.ofInt();
        valueAnimator.setInterpolator(new DecelerateInterpolator());
        valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                behavior.setTopAndBottomOffset((Integer) animation.getAnimatedValue());
                appBar.requestLayout();
            }
        });
        valueAnimator.setIntValues(0, -900);
        valueAnimator.setDuration(400);
        valueAnimator.start();
    }
    
    0 讨论(0)
提交回复
热议问题