Skip to content

考虑添加动画监听回调 #4

Description

@lufengdie

动画状态监听可以在 动画不同状态(onAnimationStart, onAnimationEnd)开始其他逻辑,这在动画使用中非常普遍。

例子中有个PathAnimView设置PathAnimHelper实现类的做法,可以添加Listener,但当PathAnimView的实现类Path值为 PathParserUtils.getPathFromArrayFloatList(StoreHousePath.getPath(""))时,该方法不可用。

最后使用如下方式实现:

private Animator.AnimatorListener animatorListener = new Animator.AnimatorListener() {

        @Override
        public void onAnimationStart(Animator animator) {

        }

        @Override
        public void onAnimationEnd(Animator animator) {

        }

        @Override
        public void onAnimationCancel(Animator animator) {

        }

        @Override
        public void onAnimationRepeat(Animator animator) {
            // TODO 下一步操作
        }
    };

    private void initAnimView(){
        fillView = findViewById(R.id.fillView);
        // 获取并设置Path
        Path sourcePath = PathParserUtils.getPathFromArrayFloatList(StoreHousePath.getPath("Thank you mcxzhang"));
        fillView.setSourcePath(sourcePath);
        fillView.setAnimTime(1500).setAnimInfinite(true);
        // 设置颜色
        fillView.setColorBg(Color.WHITE).setColorFg(Color.YELLOW);
        fillView.startAnim();
        // 获取Helper并添加动画监听器
        PathAnimHelper helper = fillView.getPathAnimHelper();
        helper.getAnimator().addListener(animatorListener);
    }

实现思路:

startAnim() 后获取helper添加Listener,因为在startAnim()之前helper.getAnimator值为空,看完源码可以理解。

如果mcxzhang抛出个接口的话,实现这个功能可能就是几行代码。

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions