您的位置:首页 > 移动开发 > Android开发

Android动画循环弹动cycleInterpolator

2015-10-27 16:15 561 查看
Android动画循环弹动cycleInterpolator
Android动画中cycleInterpolator定义属性android:cycles可以是一个动画反复执行,从而达到一个动画左右、垂直或者其他如斜方向上的反复弹动(摆动)。

写一个测试的Activity:

package zhangphil.anim;

import android.app.Activity;
import android.os.Bundle;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

ImageView image1=(ImageView) findViewById(R.id.image1);
image1.startAnimation(AnimationUtils.loadAnimation(this, R.anim.shake1));

ImageView image2=(ImageView) findViewById(R.id.image2);
image2.startAnimation(AnimationUtils.loadAnimation(this, R.anim.shake2));
}
}


image1和image2分别执行动画shake1.xml和shake2.xml 。

shake1.xml:

<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="3000"
android:fromXDelta="0.0"
android:toXDelta="100.0"
android:interpolator="@anim/cycles"/>


shake2.xml:

<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="3000"
android:fromYDelta="0.0"
android:toYDelta="100.0"
android:interpolator="@anim/cycles"/>


shake1.xml使动画水平移动,shake2.xml使动画垂直方向移动。

shake1.xml和shake2.xml都分别用到cycles.xml:

<?xml version="1.0" encoding="utf-8"?>
<cycleInterpolator xmlns:android="http://schemas.android.com/apk/res/android"
android:cycles="20" />


android:duration="3000"与android:cycles="20"联合表示在3秒内将动画执行20次。

备注:shake1.xml,shake2.xml和cycles.xml均放在res/anim目录下。



内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: