Din*_*uka 3 java mobile android android-intent android-animation
我设法为我的Image添加了一个缩放动画,使它从原始大小增长到更大的大小.但是我需要添加另一个动画代码副本,使其缩小到原始大小.我试图在布尔值为true时循环播放动画.
我玩了一些参数,但我无法使它工作.到目前为止,这是我的代码:
class AnimateButton extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... params) {
Boolean isGlowing = true; //Make it run forever
while (isGlowing) {
scal_grow = new ScaleAnimation(0, 1.2f, 0, 1.2f, Animation.RELATIVE_TO_SELF, (float) 0.5, Animation.RELATIVE_TO_SELF, (float) 0.5);
scal_grow.setDuration(1500);
scal_grow.setFillAfter(true);
runOnUiThread(new Runnable() {
@Override
public void run() {
btn_layer.setAnimation(scal_grow);
}
});
try {
Thread.sleep(1500);
} catch (Exception e) { }
//Add a reverse animation such that it goes back to the original size
}
return null;
}
}
Run Code Online (Sandbox Code Playgroud)
我应该做些什么改变?
Ram*_*mli 11
在android中,除了UIThread(主线程)之外的任何其他线程都不会发生动画和UI更新.
删除AsyncTask并尝试使用ViewPropertyAnimator,它在性能方面优于ScaleAnimation.另外,它只是一条线.
缩放:
btn_layer.animate().scaleX(1.2f).scaleY(1.2f).setDuration(1500).start();
Run Code Online (Sandbox Code Playgroud)
不规模:
btn_layer.animate().scaleX(0.8f).scaleY(0.8f).setDuration(1500).start();
Run Code Online (Sandbox Code Playgroud)
UPDATE
PropertyValuesHolder scalex = PropertyValuesHolder.ofFloat(View.SCALE_X, 1.2f);
PropertyValuesHolder scaley = PropertyValuesHolder.ofFloat(View.SCALE_Y, 1.2f);
ObjectAnimator anim = ObjectAnimator.ofPropertyValuesHolder(btn_layer, scalex, scaley);
anim.setRepeatCount(ValueAnimator.INFINITE);
anim.setRepeatMode(ValueAnimator.REVERSE);
anim.setDuration(1500);
anim.start();
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
5141 次 |
最近记录: |