给控件添加炫酷的动画效果
2017-06-15 16:20
417 查看
(重要)一个动画相关的git地址:https://github.com/daimajia/AndroidViewAnimations
demo下载地址:http://download.csdn.net/detail/android_zhengyongbo/9871490
这是我参考上面的Git地址自己封装的一个关于动画的工具类,demo里面只是呈现了一种动画animator的动画参数,如果需要其他的动画,可以去上面的git地址中的library中查询动画参数,若发现工具类中有问题,请在下面评论,谢谢!
demo下载地址:http://download.csdn.net/detail/android_zhengyongbo/9871490
1.先上工具类
import android.animation.AnimatorSet; import android.animation.ObjectAnimator; import android.view.View; import java.util.ArrayList; import java.util.List; /** * Created by zhengyongbo on 2017/6/15. */ public class AnimationUtil { private static AnimationUtil instance; private List<ObjectAnimator> animators; private AnimatorSet mAnimatorSet; public static AnimationUtil getInstance() { if(null==instance) { synchronized (AnimationUtil.class) { if (null==instance ) { instance = new AnimationUtil(); } } } return instance; } public void init() { animators = new ArrayList<>(); mAnimatorSet = new AnimatorSet(); } public List<ObjectAnimator> getAnimators() { return animators; } // 停止动画 public void stopAnimation() { try { if (mAnimatorSet != null) { mAnimatorSet.cancel(); if (animators.size() > 0) { for (int i = 0; i < animators.size(); i++) { animators.get(i).cancel(); } animators.clear(); } } } catch (Exception e) { } } /** * target: View animators: 动画,可以是一个效果,也可以多个效果,这些效果依次顺序执行 duration:多长时间内动画执行完 * repeatCount:动画循环播放次数 */ public void startAnimation(View target, List<ObjectAnimator> animators, long duration, int repeatCount) { try { if (animators.size() <= 0) { return; } for (int i = 0; i < animators.size(); i++) { // 动画效果不限,依次执行 mAnimatorSet.playTogether(animators.get(i)); // 设置动画循环播放次数 animators.get(i).setRepeatCount(repeatCount); } // 设置动画再多长时间内播完 mAnimatorSet.setDuration(duration); // 开始动画 mAnimatorSet.start(); } catch (Exception e) { } } }
2.使用
import android.animation.ObjectAnimator; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.ImageView; public class MainActivity extends AppCompatActivity { private ImageView imageView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); imageView = (ImageView) findViewById(R.id.tv); // https://github.com/daimajia/AndroidViewAnimations // 根据上面的项目改编,需要的animator参数在上面查找 AnimationUtil.getInstance().init(); // 添加动画效果参数,可以是一个也可以是多个 ObjectAnimator animator = ObjectAnimator.ofFloat(imageView, "scaleX", 1, 1.25f, 0.75f, 1.15f, 1); AnimationUtil.getInstance().getAnimators().add(an 157eb imator); ObjectAnimator animator1 = ObjectAnimator.ofFloat(imageView, "scaleY", 1, 0.75f, 1.25f, 0.85f, 1); AnimationUtil.getInstance().getAnimators().add(animator1); // 开始动画 AnimationUtil.getInstance().startAnimation(imageView,AnimationUtil.getInstance().getAnimators(), 1200, 9); findViewById(R.id.button).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // 停止动画 AnimationUtil.getInstance().stopAnimation(); } }); } }
这是我参考上面的Git地址自己封装的一个关于动画的工具类,demo里面只是呈现了一种动画animator的动画参数,如果需要其他的动画,可以去上面的git地址中的library中查询动画参数,若发现工具类中有问题,请在下面评论,谢谢!
相关文章推荐
- ios控件加载图片,plist,懒加载,序列帧动画,添加动画效果。
- ios给控件添加动画效果
- 仿QQ好友动态添加说说、图片菜单滑动移进移出效果--在指定控件下面显示popupwindow动画不移效果
- 添加购物车控件(增加或减少数字)有动画效果
- IOs-控件上添加动画效果
- iOS工作记录7 :ios控件加载图片,plist,懒加载,序列帧动画,添加动画效果(实用例子)
- 为控件添加动画效果(安卓)
- 给控件添加动画效果
- 给View控件添加动画效果
- IOS 给一个控件添加一个动画组的效果
- iOS 开发中问题 ——使用xib拖拽控件操作其约束并添加动画没有效果的问题
- android 给LinearLayout中添加一定数量的控件,并让着一定数量的控件从右到左移动,每隔若干秒停顿一下,最后一个view链接第一个view,然后继续移动循环往复,形成一个死循环简单动画效果
- 游戏动画炫酷效果:零距离C++开发实战
- 自己动手丰衣足食,为Zepto添加Slide动画效果
- viewpager切换添加动画效果viewpager切换添加动画效果--IT蓝豹
- CSS3使用AnimationEnd为同一个元素添加多个动画效果
- 安卓购物车添加商品动画效果
- ViewPager添加动画效果
- #686 – 使用动画是控件具有闪烁效果(Using Animation to Make an Image Pulse)
- intent跳转时添加动画效果实例