ExpectAnim-属性动画链式调用

 ExpectAnim开源地址

介绍:

把属性动画封装成链式调用的形式。

运行效果:

使用说明:

In your module Download

compile 'com.github.florent37:expectanim:1.0.0'

sample (2).gif

上面动画的代码:

new ExpectAnim()

                .expect(avatar)
                .toBe(
                        bottomOfParent().withMarginDp(16),
                        leftOfParent().withMarginDp(16),
                        width(40).toDp().keepRatio()
                )

                .expect(name)
                .toBe(
                        toRightOf(avatar).withMarginDp(16),
                        sameCenterVerticalAs(avatar),
                        toHaveTextColor(Color.WHITE)
                )

                .expect(subname)
                .toBe(
                        toRightOf(name).withMarginDp(5),
                        sameCenterVerticalAs(name),
                        toHaveTextColor(Color.WHITE)
                )

                .expect(follow)
                .toBe(
                        rightOfParent().withMarginDp(4),
                        bottomOfParent().withMarginDp(12),
                        toHaveBackgroundAlpha(0f)
                )

                .expect(message)
                .toBe(
                        aboveOf(follow).withMarginDp(4),
                        rightOfParent().withMarginDp(4),
                        toHaveBackgroundAlpha(0f)
                )

                .expect(bottomLayout)
                .toBe(
                        atHisOriginalPosition()
                )

                .expect(content)
                .toBe(
                        atHisOriginalPosition(),
                        visible()
                )

                .toAnimation()
                .setDuration(1500)

                .start();

跟随滚动

scroll.gif

使用setPercent来设置动画当前的进度

this.expectAnimMove = new ExpectAnim()
                .expect(username)
                .toBe(
                        toRightOf(avatar).withMarginDp(16),
                        sameCenterVerticalAs(avatar),
                        alpha(0.5f)
                )

                .expect(avatar)
                .toBe(
                        topOfParent(),
                        leftOfParent().withMarginDp(16),
                        scale(0.5f, 0.5f)
                )
                .expect(follow)
                .toBe(
                        rightOfParent().withMarginDp(16),
                        sameCenterVerticalAs(avatar)
                )

                .expect(backbground)
                .toBe(
                        height(height).withGravity(Gravity.LEFT, Gravity.TOP)
                )

                .toAnimation();

scrollView.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {
    @Override
    public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
        final float percent = (scrollY * 1f) / v.getMaxScrollAmount();

        expectAnimMove.setPercent(percent);
    }
});

直接应用动画

使用setNow直接开始动画

new ExpectAnim()
                .expect(view)
                .toBe(
                        outOfScreen(Gravity.BOTTOM)
                )
                .toAnimation()
                .setNow();

所有的expectation

new ExpectAnim()
                .expect(view)
                .toBe(

                    //.withMargin(marginPx)
                    //.withMarginDp(margin)
                    //.withMarginDimen(R.dimen.margin)

                    toRightOf(view)
                    toLeftOf(view)
                    belowOf(view)
                    aboveOf(view)

                    atHisOriginalPosition()


                    sameCenterAs(view, horizontal, vertical)
                    sameCenterHorizontalAs(view)
                    sameCenterVerticalAs(view)
                    centerInParent(horizontal, vertical)
                    centerVerticalInParent()
                    centerHorizontalInParent()

                    centerBetweenViews(view1, view2, horizontal, vertical)
                    centerBetweenViewAndParent(otherView, horizontal, vertical, toBeOnRight, toBeOnBottom)

                    topOfParent()
                    rightOfParent()
                    bottomOfParent()
                    leftOfParent()

                    alignBottom(otherView)
                    alignTop(otherView)
                    alignLeft(otherView)
                    alignRight(otherView)

                    outOfScreen(gravitiy)  //Gravity.LEFT / Gravity.RIGHT / Gravity.TOP / Gravity.BOTTOM

                    alpha(alpha)
                    sameAlphaAs(otherView)
                    visible()
                    invisible()

                    //.keepRatio()
                    //.withGravity(horizontalGravity, verticalGravity)

                    atHisOriginalScale()

                    scale(scaleX, scaleY)
                    height(height)
                    width(width)
                    sameScaleAs(otherView)
                    sameWidthAs(otherView)
                    sameHeightAs(otherView)


                    toHaveTextColor(textColor)
                    toHaveBackgroundAlpha(alpha)

                )

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值