/*
软件作者:https://xuhss.com/oxox/pro
*/
/**
* 作者: 家
* QQ: 203118908
* 功能: 动画ObjectAnimator例子
* 备注: 属性动画,顾名思义,更改view的属性
*/
'ui';
importClass(java.lang.Runnable);
importClass(android.animation.ObjectAnimator)
importClass(android.animation.PropertyValuesHolder)
importClass(android.animation.ValueAnimator)
importClass(android.animation.AnimatorSet)
importClass(android.view.animation.AccelerateInterpolator)
importClass(android.view.animation.TranslateAnimation)
importClass(android.animation.ObjectAnimator)
importClass(android.animation.TimeInterpolator)
// importClass(android.support.v4.view.animation.FastOutLinearInInterpolator)
// importClass(android.support.v4.view.animation.FastOutSlowInInterpolator)
// importClass(android.support.v4.view.animation.LinearOutSlowInInterpolator)
// importClass(android.support.v7.app.AppCompatActivity)
importClass(android.os.Bundle)
importClass(android.view.View)
importClass(android.view.Window)
importClass(android.view.WindowManager)
importClass(android.view.animation.AccelerateDecelerateInterpolator)
importClass(android.view.animation.AccelerateInterpolator)
importClass(android.view.animation.AnticipateInterpolator)
importClass(android.view.animation.AnticipateOvershootInterpolator)
importClass(android.view.animation.BounceInterpolator)
importClass(android.view.animation.CycleInterpolator)
importClass(android.view.animation.DecelerateInterpolator)
importClass(android.view.animation.LinearInterpolator)
importClass(android.view.animation.OvershootInterpolator)
importClass(android.view.animation.PathInterpolator)
importClass(android.widget.Button)
importClass(android.widget.ImageView)
importClass(android.widget.TextView)
var myColor = function () {
return '#' + getRndColor()
}
ui.layout(
<vertical>
<scroll>
<vertical id='parent'>
<button id='ObjectAnimator多个动画' textSize='20sp'>ObjectAnimator多个动画</button>
<button id='PropertyValuesHolder多个动画' textSize='20sp'>PropertyValuesHolder多个动画</button>
<button id='自定义动画同时执行' textSize='20sp'>自定义动画同时执行</button>
<button id='自定义动画先后执行' textSize='20sp'>自定义动画先后执行</button>
<button id='透明' textSize='20sp'>透明</button>
<button id='旋转' textSize='20sp'>旋转</button>
<button id='插值器_头慢中快尾慢' textSize='20sp'>插值器_头慢中快尾慢</button>
<button id='插值器_头快尾慢' textSize='20sp'>插值器_头快尾慢</button>
<button id='插值器_慢慢加快' textSize='20sp'>插值器_慢慢加快</button>
<button id='插值器_弹射' textSize='20sp'>插值器_弹射</button>
<button id='自定义动画完成度_时间完成度曲线' textSize='20sp'>自定义动画完成度_时间完成度曲线</button>
<button id='插值器_惯性' textSize='20sp'>插值器_惯性</button>
<button id='插值器_惯性2' textSize='20sp'>插值器_惯性2</button>
<button id='插值器_弹性的小球掉到地上' textSize='20sp'>插值器_弹性的小球掉到地上</button>
<button id='插值器_类似sin函数' textSize='20sp'>插值器_类似sin函数</button>
<button id='绕X轴旋转' textSize='20sp'>绕X轴旋转</button>
<button id='在X轴上的平移' textSize='20sp'>在X轴上的平移</button>
<button id='在Y轴上的平移' textSize='20sp'>在Y轴上的平移</button>
<button id='在X轴上的缩放' textSize='20sp'>在X轴上的缩放</button>
<button id='在Y轴上的缩放' textSize='20sp'>在Y轴上的缩放</button>
<button id='更换背景颜色' textSize='20sp'>更换背景颜色</button>
<button id='顺序执行动画' textSize='20sp'>顺序执行动画</button>
<button id='同时执行动画' textSize='20sp'>同时执行动画</button>
<button id='平移_虚假移动_真身未动' textSize='20sp'>平移_虚假移动_真身未动</button>
</vertical>
</scroll>
</vertical>
)
ui.post(
function () {
var parent = ui.parent
var sonsNum = parent.getChildCount()
for (var i = 0; i < sonsNum; i++) {
var son = parent.getChildAt(i)
log(son.getText())
var color = rndColor()
log(color)
son.setBackgroundColor(color)
}
}, 300
)
ui.插值器_头慢中快尾慢.on('click', () => {
//更加丰富的控制效果
var view = ui.插值器_头慢中快尾慢
animator = ObjectAnimator.ofFloat(view, "translationY", 0, -600, 0);
mTimeInterpolator = new AccelerateDecelerateInterpolator();
animator.setInterpolator(mTimeInterpolator);
animator.setDuration(3000); //动画时间
animator.start();
})
ui.插值器_头快尾慢.on('click', () => {
//更加丰富的控制效果
var view = ui.插值器_头快尾慢
animator = ObjectAnimator.ofFloat(view, "translationY", 0, -1000, 0);
mTimeInterpolator = new DecelerateInterpolator();
animator.setInterpolator(mTimeInterpolator);
animator.setDuration(3000); //动画时间
animator.start();
})
ui.插值器_慢慢加快.on('click', () => {
var view = ui.插值器_慢慢加快
animator = ObjectAnimator.ofFloat(view, "translationY", 0, -2000, 0);
mTimeInterpolator = new AccelerateInterpolator();
animator.setInterpolator(mTimeInterpolator);
animator.setDuration(3000);
animator.start();
})
ui.插值器_弹射.on('click', () => {
var view = ui.插值器_弹射
animator = ObjectAnimator.ofFloat(view, "translationY", 0, -300, 0);
mTimeInterpolator = new AnticipateInterpolator();
animator.setInterpolator(mTimeInterpolator);
animator.setDuration(3000);
animator.start();
})
ui.插值器_惯性2.on('click', () => {
var view = ui.插值器_惯性2
animator = ObjectAnimator.ofFloat(view, "translationY", 0, -200, 0);
mTimeInterpolator = new OvershootInterpolator();
animator.setInterpolator(mTimeInterpolator);
animator.setDuration(3000);
animator.start();
})
ui.插值器_惯性.on('click', () => {
var view = ui.插值器_惯性
animator = ObjectAnimator.ofFloat(view, "translationY", 0, -200, 0);
mTimeInterpolator = new AnticipateOvershootInterpolator();
animator.setInterpolator(mTimeInterpolator);
animator.setDuration(3000);
animator.start();
})
ui.插值器_弹性的小球掉到地上.on('click', () => {
var view = ui.插值器_弹性的小球掉到地上
animator = ObjectAnimator.ofFloat(view, "translationY", 0, -600, 0);
mTimeInterpolator = new BounceInterpolator();
animator.setInterpolator(mTimeInterpolator);
animator.setDuration(3000);
animator.start();
})
ui.插值器_类似sin函数.on('click', () => {
var view = ui.插值器_类似sin函数
// 为了显示效果,我们先把按钮升高一点,然后再执行这个插值器效果
animator往上走 = ObjectAnimator.ofFloat(view, "translationY", 0, -600);
animator = ObjectAnimator.ofFloat(view, "translationY", 0, -600);
mTimeInterpolator = new CycleInterpolator(6);
animator.setInterpolator(mTimeInterpolator);
set = new AnimatorSet();
set.playSequentially(animator往上走, animator);
set.setDuration(3000);
set.start();
})
ui.自定义动画完成度_时间完成度曲线.on('click', () => {
var view = ui.自定义动画完成度_时间完成度曲线
// 为了显示效果,我们先把按钮升高一点,然后再执行这个插值器效果
var path = new android.graphics.Path();
// 先以「动画完成度 : 时间完成度 = 1 : 1」的速度匀速运行 25%
path.lineTo(0.25, 0.25);
// 然后瞬间跳跃到 150% 的动画完成度
path.moveTo(0.25, 1.5);
// 再匀速倒车,返回到目标点
path.lineTo(1, 1);
animator = ObjectAnimator.ofFloat(view, "translationY", 0, 100, 0);
mTimeInterpolator = new PathInterpolator(path);
animator.setInterpolator(mTime