android+动画队列,GitHub - canyinghao/CanAnimation: 使用android属性动画写的一个库,可组建动画队列,可实现同时、顺序、重复播放等。...

CanAnimation

使用android属性动画写的一个库,可组建动画队列,可实现同时、顺序、重复播放等。

CanAnimation.gif

##添加依赖

compile 'com.canyinghao:cananimation:1.0.3'

使用方式

1. 使用方法

CanAnimation是一个动画库,可按队列播放动画。CanObjectAnimator类是使用ObjectAnimator写的动画,使用时需要传一些初始值,不然会有问题,比如移动到(500,500),你下一个移动动画要传(500,500)才能连上上一个动画,不方便。所以推荐使用CanValueAnimator类。CanValueAnimator类继承自ValueAnimator,通过反射设置属性值,而且重写start()方法,在start()方法中获取view的初始值,不用传如初始值,使用相当方便。

CanObjectAnimator使用代码:

CanObjectAnimator builder = CanObjectAnimator.on(view);

animationSequence(builder.moveTo(center.x, center.y, 0),

animationTogether(builder.moveTo(center.x,newPos.x,center.y, newPos.y, 2),

builder.rotateTo(360, 2),

builder.color(Color.BLUE, Color.RED, 2),

builder.colorText(Color.WHITE, Color.BLUE, 2)

),

animationTogether(builder.scaleTo(0.5f, 0.5f,2),

builder.rotateTo(720,2),

animationSequence(

builder.color(Color.RED, Color.BLACK, 0.3f),

builder.color(Color.BLACK, Color.RED, 0.3f),

builder.color(Color.RED, Color.GREEN, 0.3f),

builder.color(Color.GREEN, Color.RED, 0.3f),

builder.color(Color.RED, Color.YELLOW, 0.3f),

builder.color(Color.YELLOW, Color.RED, 0.3f),

builder.color(Color.RED, Color.BLUE, 0.3f)

)

),

animationTogether(

builder.moveTo(newPos.x,center.x, newPos.y,center.y, 2),

builder.scaleTo(0.5f,2, 0.5f,2, 2),

builder.rotateTo(360, 2),

builder.color(Color.BLUE, Color.GRAY, 2),

builder.colorText(Color.BLUE, Color.WHITE, 2)

),

CanAnimation.run(new Runnable() {

@Override

public void run() {

Snackbar.make(toolbar, "动画播放完毕", Snackbar.LENGTH_SHORT).show();

}

})

).start();

CanValueAnimator使用代码:

CanValueAnimator.Builder builder = CanValueAnimator.Builder.on(view);

animationSequence(builder.moveTo(center.x, center.y, 0),

animationTogether(builder.moveTo(newPos.x, newPos.y, 2),

builder.rotateTo(360, 2),

builder.color(Color.BLUE, Color.RED, 2),

builder.colorText(Color.WHITE, Color.BLUE, 2)

),

animationTogether(builder.scaleTo(0.5f, 0.5f,2),

builder.rotateTo(720,2),

animationSequence(

builder.color(Color.RED, Color.BLACK, 0.3f),

builder.color(Color.BLACK, Color.RED, 0.3f),

builder.color(Color.RED, Color.GREEN, 0.3f),

builder.color(Color.GREEN, Color.RED, 0.3f),

builder.color(Color.RED, Color.YELLOW, 0.3f),

builder.color(Color.YELLOW, Color.RED, 0.3f),

builder.color(Color.RED, Color.BLUE, 0.3f)

)

),

animationTogether(

builder.moveTo(center.x, center.y, 2),

builder.scaleTo(2, 2, 2),

builder.rotateTo(360, 2),

builder.color(Color.BLUE, Color.GRAY, 2),

builder.colorText(Color.BLUE, Color.WHITE, 2)

),

CanAnimation.run(new Runnable() {

@Override

public void run() {

Snackbar.make(toolbar, "动画播放完毕", Snackbar.LENGTH_SHORT).show();

}

})

).start();

2. 翻转动画

翻转动画通过使用ViewFlipper和Camera等实现。

使用代码:

public class FlipperAnimeActivity extends AppCompatActivity {

@Bind(R.id.vf)

ViewFlipper vf;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.flipper);

ButterKnife.bind(this);

vf.postDelayed(new Runnable() {

@Override

public void run() {

CanFlipAnimation.flipForever(vf, CanFlipAnimation.FlipDirection.LEFT_RIGHT,1000,null,0);

}

},1000);

}

}

开发者

386a0642ec579805e317314c3b7a27d9.png

canyinghao:

License

Copyright 2016 canyinghao

Licensed under the Apache License, Version 2.0 (the "License");

you may not use this file except in compliance with the License.

You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software

distributed under the License is distributed on an "AS IS" BASIS,

WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

See the License for the specific language governing permissions and

limitations under the License.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值