登录 立即注册
安币:

安卓巴士 - 安卓开发 - Android开发 - 安卓 - 移动互联网门户

android实现层次效果源码

[复制链接]
来自: jjcodecode 分类: Android精品源码 上传时间: 2017-10-12 10:26:15
Tag:

项目介绍:

In your module Download

compile 'com.github.florent37:expectanim:1.0.7'
This code describe the video above

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(
                    atItsOriginalPosition()
            )

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

            .toAnimation()
            .setDuration(1500)

            .start();

Follow scroll

gif

Use setPercent to apply modify the current step of the animation

Exemple with a scrollview

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.START, 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);
}

});
Concat

You can play an anim after one other using ExpectAnim.concat (static method)

ExpectAnim.concat(

            new ExpectAnim()
                    .expect(image1)
                    .toBe(
                            withCameraDistance(500f),
                            flippedHorizontally()
                    )
                    .toAnimation()
                    .setDuration(1000),
            new ExpectAnim()
                    .expect(image2)
                    .toBe(
                            withCameraDistance(1000f),
                            flippedVertically()
                    )
                    .toAnimation()
                    .setDuration(500)
            )
            .start()

Apply directly

Use setNow to apply directly the transformation

new ExpectAnim()

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

Reset

Use reset to return to the initial state of views

expectAnim.reset():
List of expectations

new ExpectAnim()

            .expect(view)
            .toBe(

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

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

                atItsOriginalPosition()
                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)

                atItsOriginalScale()

                scale(scaleX, scaleY)
                height(height)
                width(width)
                sameScaleAs(otherView)
                sameWidthAs(otherView)
                sameHeightAs(otherView)
                toHaveTextColor(textColor)
                toHaveBackgroundAlpha(alpha)

                rotated(rotation)
                vertical(bottomOfViewAtLeft)
                atItsOriginalRotation()
            )

Proguard

-keep class com.github.florent37.expectanim.{ ; }
-dontwarn com.github.florent37.expectanim.**

相关源码推荐:

我来说两句
*滑动验证:
所有评论(5)
设女郎 2017-10-12 10:30:28
支持楼主,支持安卓巴士!
回复
tintins 2017-10-12 10:30:36
安卓巴士是个不错的网站,我来顶个贴~
回复
humanboy 2017-10-12 10:30:43
感觉楼主很用心,辛苦啦~
回复
Mr_Zhao 2017-10-12 10:30:51
支持楼主,支持安卓巴士!
回复
是个宝宝 2017-10-12 10:30:58
楼主威武,以后多发干货,多办活动~!
回复
深思 2017-10-12 10:31:10
支持楼主,支持安卓巴士!
回复
QQ_696FD5 2017-10-12 11:08:56
精华内容,楼主V5!
回复
提取码:  下载次数:2 状态:已购或VIP 售价:20(原价:20)金钱 下载权限:限制会员 
582 0 2
代码贡献英雄榜
用户名 下载数
联系我们
首页/微信公众账号投稿

帖子代码编辑/版权问题

QQ:435399051,769657487

如何获得代码达人称号

如何成为签约作者

联系我们
关闭
合作电话:
13802416937
Email:
435399051@qq.com
商务市场合作/投稿
问题反馈及帮助
联系我们

广告投放| 申请友链|手机版|站点统计|安卓巴士 ( 粤ICP备15117877号 )

快速回复 返回顶部 返回列表