Whatsapp like Collapsing Toolbar

后端 未结 4 1524
挽巷
挽巷 2020-11-28 06:33

In my app, I would like to implement Whatsapp home page like collapsible toolbar. That is, while scrolling down the list, the toolbar should go up and the tabs should pin at

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-28 07:00

    This library will help you

    This is a very simple library for Android that allows you to stick an header to a scrollable view and easily apply animation to it

    EDIT: To use the StikkyHeader library, you just need 3 lines:

    StikkyHeaderBuilder.stickTo(mListView)
    .setHeader(R.id.header, containerLayout)
    .minHeightHeader(250)
    .build();
    

    Example:

    public class IconAnimator extends HeaderStikkyAnimator {
    
    @Override
    public AnimatorBuilder getAnimatorBuilder() {
    
        View viewToAnimate = getHeader().findViewById(R.id.icon);
        Point point = new Point(50,100) // translate to the point with coordinate (50,100);
        float scaleX = 0.5f //scale to the 50%
        float scaleY = 0.5f //scale to the 50%
        float fade = 0.2f // 20% fade
    
        AnimatorBuilder animatorBuilder = AnimatorBuilder.create()
            .applyScale(viewToAnimate, scaleX, scaleY)
            .applyTranslation(viewToAnimate, point)
            .applyFade(viewToAnimate, fade);
    
        return animatorBuilder;
    }
    }
    

    and then set the animator to the StikkyHeader:

     StikkyHeaderBuilder.stickTo(mListView)
    .setHeader(R.id.header, containerLayout)
    .minHeightHeader(250)
    .animator(new IconAnimator())
    .build();
    

提交回复
热议问题