Android-nineoldandroids框架的使用

来源:互联网 发布:大学java 教不教线程 编辑:程序博客网 时间:2024/05/18 07:48

平移动画:

ObjectAnimator.ofFloat(button,"translationX",100,50,100,50,100).setDuration(1000).start(); // 水平移动
ObjectAnimator.ofFloat(button,"translationY",100,50,100,50,100).setDuration(1000).start(); // 竖直移动


缩放动画:

ObjectAnimator.ofFloat(button,"scaleX",0.5f,1,0.5f,1,0.5f).setDuration(1000).start(); // 水平方向缩放
ObjectAnimator.ofFloat(button,"scaleY",0.5f,1,0.5f,1,0.5f).setDuration(1000).start(); // 竖直方向缩放
// 程序员可以根据需求设置锚点来改变缩放的形态,默认情况下锚点的位置是[0.5,0.5],即控件中心点的位置
button.setPivotX(1.0f); // 更改控件锚点的X坐标位置button.setPivotY(1.0f); // 更改控件锚点的Y坐标位置

透明度动画

ObjectAnimator.ofFloat(button,"alpha",0.1f).setDuration(1500).start(); 

旋转动画

ObjectAnimator.ofFloat(button,"rotationX",30).setDuration(1500).start(); // 沿X轴旋转
ObjectAnimator.ofFloat(button,"rotationY",30).setDuration(1500).start(); // 沿Y轴旋转

对动画进行监听动作时的写法:

ObjectAnimator animator = ObjectAnimator.ofFloat(button,"rotationY",30).setDuration(1500); // 动画的开始,结束,取消,重复动作监听animator.addListener(new Animator.AnimatorListener() {     @Override     public void onAnimationStart(Animator animation) {              }     @Override     public void onAnimationEnd(Animator animation) {     }     @Override     public void onAnimationCancel(Animator animation) {     }     @Override     public void onAnimationRepeat(Animator animation) {     } }); // 动画更新监听 animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {     @Override     public void onAnimationUpdate(ValueAnimator animation) {              } }); animator.setDuration(1500); // 持续时间 animator.setStartDelay(3000); // 设置延时 animator.start();

0 0
原创粉丝点击