下面列出了android.view.animation.ScaleAnimation#setRepeatCount() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* ���Ŷ���
*
* @param v
*/
public void scale(View v) {
/*
* ����1��x������ʼ��С(1f��ʾԭͼ��С) ����2��x������ֹ��С(0.2f��ʾԭͼ��0.2��)
* ����3��y������ʼ��С(1f��ʾԭͼ��С) ����4��y������ֹ��С(0.2f��ʾԭͼ��0.2��) ����5���������ĵ�x��ȡֵ�IJ��շ�ʽ
* ����6: ���ĵ�x���ȡֵ(0.5f��ʾ�����ԭͼ��0.5��) ����7���������ĵ�y��ȡֵ���շ�ʽ ����8:
* ���ĵ�y���ȡֵ(0.5f��ʾ�����ԭͼ��0.5��)
*/
ScaleAnimation rotate = new ScaleAnimation(4f, 0.2f, 4f, 0.2f,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
0.5f);
// ������ʾʱ�䳤��
rotate.setDuration(2000);
// �����ظ�����
rotate.setRepeatCount(2);
// ���ö����ظ���ģʽ
rotate.setRepeatMode(Animation.REVERSE);
// ��ImageView�ϲ��Ŷ���
iv.startAnimation(rotate);
}
/**
* 初始化动画集
* @return
*/
private AnimationSet initAnimationSet() {
AnimationSet as = new AnimationSet(true);
//缩放度:变大两倍
ScaleAnimation sa = new ScaleAnimation(1f, 2f, 1f, 2f,
ScaleAnimation.RELATIVE_TO_SELF, 0.5f,
ScaleAnimation.RELATIVE_TO_SELF, 0.5f);
sa.setDuration(show_spacing_time * 3);
sa.setRepeatCount(Animation.INFINITE);// 设置循环
//透明度
AlphaAnimation aa = new AlphaAnimation(1, 0.1f);
aa.setDuration(show_spacing_time * 3);
aa.setRepeatCount(Animation.INFINITE);//设置循环
as.addAnimation(sa);
as.addAnimation(aa);
return as;
}
/**
* 中间的View动画播放
*/
private void playCenter() {
AnimationSet animationSet = new AnimationSet(false);
ScaleAnimation scaleSmall = new ScaleAnimation(1.0f, 0.6f, 1.0f, 0.6f,Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
ScaleAnimation scaleBig = new ScaleAnimation(1.0f, 5.0f/3, 1.0f, 5.0f/3,Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
scaleBig.setDuration(2*1000);
scaleBig.setInterpolator(interpolator);
scaleSmall.setDuration(2*1000);
scaleSmall.setStartOffset(2*1000);
scaleSmall.setRepeatCount(-1);
scaleSmall.setFillEnabled(true);
scaleSmall.setFillAfter(true);
scaleBig.setStartOffset(2*1000);
scaleBig.setRepeatCount(-1);
scaleBig.setFillEnabled(true);
scaleBig.setFillAfter(true);
scaleSmall.setInterpolator(interpolator);
animationSet.addAnimation(scaleBig);
animationSet.addAnimation(scaleSmall);
center.startAnimation(animationSet);
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
WIDTH = w;
HEIGHT = h;
scaleAnimation = new ScaleAnimation(1.0f, zoomScale, 1.0f, zoomScale, w / 2, h / 2);
scaleAnimation.setDuration(zoomDuration);
scaleAnimation.setRepeatMode(Animation.REVERSE);
scaleAnimation.setRepeatCount(1);
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
WIDTH = w;
HEIGHT = h;
scaleAnimation = new ScaleAnimation(1.0f, zoomScale, 1.0f, zoomScale, w / 2, h / 2);
scaleAnimation.setDuration(zoomDuration);
scaleAnimation.setRepeatMode(Animation.REVERSE);
scaleAnimation.setRepeatCount(1);
}
/**
格子触摸时的动画
*/
public Animation getItemTouchAnimation() {
ScaleAnimation scaleAnimation = new ScaleAnimation(1, .7F, 1, .7F, Animation.RELATIVE_TO_SELF, .5F, Animation.RELATIVE_TO_SELF, .5F);
scaleAnimation.setDuration(130);
scaleAnimation.setRepeatCount(1);
scaleAnimation.setRepeatMode(Animation.REVERSE);
return scaleAnimation;
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh)
{
super.onSizeChanged(w, h, oldw, oldh);
WIDTH = w;
HEIGHT = h;
scaleAnimation = new ScaleAnimation(1.0f, zoomScale, 1.0f, zoomScale, w / 2, h / 2);
scaleAnimation.setDuration(zoomDuration);
scaleAnimation.setRepeatMode(Animation.REVERSE);
scaleAnimation.setRepeatCount(1);
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh)
{
super.onSizeChanged(w, h, oldw, oldh);
WIDTH = w;
HEIGHT = h;
scaleAnimation = new ScaleAnimation(1.0f, zoomScale, 1.0f, zoomScale, w / 2, h / 2);
scaleAnimation.setDuration(zoomDuration);
scaleAnimation.setRepeatMode(Animation.REVERSE);
scaleAnimation.setRepeatCount(1);
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
WIDTH = w;
HEIGHT = h;
scaleAnimation = new ScaleAnimation(1.0f, zoomScale, 1.0f, zoomScale, w / 2, h / 2);
scaleAnimation.setDuration(zoomDuration);
scaleAnimation.setRepeatMode(Animation.REVERSE);
scaleAnimation.setRepeatCount(1);
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
WIDTH = w;
HEIGHT = h;
scaleAnimation = new ScaleAnimation(1.0f, zoomScale, 1.0f, zoomScale, w / 2, h / 2);
scaleAnimation.setDuration(zoomDuration);
scaleAnimation.setRepeatMode(Animation.REVERSE);
scaleAnimation.setRepeatCount(1);
}
private Animation getScaleAnimation() {
ScaleAnimation scaleAnimation = new ScaleAnimation(1f, 2f,
1f, 2f,
getWidth() / 2, getHeight() / 2);
scaleAnimation.setDuration(2000);
scaleAnimation.setRepeatCount(2);
scaleAnimation.setFillAfter(true);
scaleAnimation.setFillBefore(false);
scaleAnimation.setRepeatMode(Animation.REVERSE);
return scaleAnimation;
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
WIDTH = w;
HEIGHT = h;
scaleAnimation = new ScaleAnimation(1.0f, zoomScale, 1.0f, zoomScale, w / 2, h / 2);
scaleAnimation.setDuration(zoomDuration);
scaleAnimation.setRepeatMode(Animation.REVERSE);
scaleAnimation.setRepeatCount(1);
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
WIDTH = w;
HEIGHT = h;
scaleAnimation = new ScaleAnimation(1.0f, zoomScale, 1.0f, zoomScale, w / 2, h / 2);
scaleAnimation.setDuration(zoomDuration);
scaleAnimation.setRepeatMode(Animation.REVERSE);
scaleAnimation.setRepeatCount(1);
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh)
{
super.onSizeChanged(w, h, oldw, oldh);
WIDTH = w;
HEIGHT = h;
scaleAnimation = new ScaleAnimation(1.0f, zoomScale, 1.0f, zoomScale, w / 2, h / 2);
scaleAnimation.setDuration(zoomDuration);
scaleAnimation.setRepeatMode(Animation.REVERSE);
scaleAnimation.setRepeatCount(1);
}
private void animateOnTheEdge() {
if (!adapter.disableZoomAnimationsOnChangePage()) {
View v = getDraggedView();
ScaleAnimation scale = new ScaleAnimation(.667f, 1.5f, .667f, 1.5f, v.getMeasuredWidth() * 3 / 4, v.getMeasuredHeight() * 3 / 4);
scale.setDuration(200);
scale.setRepeatMode(Animation.REVERSE);
scale.setRepeatCount(Animation.INFINITE);
v.clearAnimation();
v.startAnimation(scale);
}
}
public static void wave(final View layer, float scale, int duration, float stepOffset) {
final ScaleAnimation scaleAnimation = new ScaleAnimation(1.0f, scale, 1.0f, scale, Animation.RELATIVE_TO_SELF, (float) 0.5, Animation.RELATIVE_TO_SELF, (float) 0.5);
scaleAnimation.setDuration(duration);
scaleAnimation.setInterpolator(new OffsetCycleInterpolator(stepOffset));
scaleAnimation.setRepeatCount(Animation.INFINITE);
layer.clearAnimation();
layer.startAnimation(scaleAnimation);
}
/**
* Animates the layout when clicked. The animation used depends on whether the
* device is round or rectangular.
*/
public void onLayoutClicked(View view) {
if (mRectBackground != null) {
ScaleAnimation scaleAnimation = new ScaleAnimation(1.0f, 0.7f, 1.0f, 0.7f,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
scaleAnimation.setDuration(300);
scaleAnimation.setRepeatCount(1);
scaleAnimation.setRepeatMode(Animation.REVERSE);
mRectBackground.startAnimation(scaleAnimation);
}
if (mRoundBackground != null) {
mRoundBackground.animate().rotationBy(360).setDuration(300).start();
}
}
/**
* ���Ŷ���
*
* @param v
*/
public void scale(View v) {
/*
* ����1��x������ʼ��С(1f��ʾԭͼ��С)
* ����2��x������ֹ��С(0.2f��ʾԭͼ��0.2��)
* ����3��y������ʼ��С(1f��ʾԭͼ��С)
* ����4��y������ֹ��С(0.2f��ʾԭͼ��0.2��)
* ����5���������ĵ�x��ȡֵ�IJ��շ�ʽ
* ����6: ���ĵ�x���ȡֵ(0.5f��ʾ�����ԭͼ��0.5��)
* ����7���������ĵ�y��ȡֵ���շ�ʽ
* ����8:���ĵ�y���ȡֵ(0.5f��ʾ�����ԭͼ��0.5��)
*/
ScaleAnimation rotate = new ScaleAnimation(4f, 0.2f, 4f, 0.2f,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
0.5f);
// ������ʾʱ�䳤��
rotate.setDuration(2000);
// �����ظ�����
rotate.setRepeatCount(2);
// ���ö����ظ���ģʽ
rotate.setRepeatMode(Animation.REVERSE);
// ��ImageView�ϲ��Ŷ���
iv.startAnimation(rotate);
}
/**
* Animates the layout when clicked. The animation used depends on whether the
* device is round or rectangular.
*/
public void onLayoutClicked(View view) {
if (mRectBackground != null) {
ScaleAnimation scaleAnimation = new ScaleAnimation(1.0f, 0.7f, 1.0f, 0.7f,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
scaleAnimation.setDuration(300);
scaleAnimation.setRepeatCount(1);
scaleAnimation.setRepeatMode(Animation.REVERSE);
mRectBackground.startAnimation(scaleAnimation);
}
if (mRoundBackground != null) {
mRoundBackground.animate().rotationBy(360).setDuration(300).start();
}
}
public void mahang (View view){
AnimationSet set = new AnimationSet(false);
TranslateAnimation tras = new TranslateAnimation(
Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 2,
Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 2);
// ������ʾʱ�䳤��
tras.setDuration(2000);
// �����ظ�����
tras.setRepeatCount(2);
// ���ö����ظ���ģʽ
tras.setRepeatMode(Animation.REVERSE);
RotateAnimation rotate = new RotateAnimation(360, 0,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
0.5f);
// ������ʾʱ�䳤��
rotate.setDuration(2000);
// �����ظ�����
rotate.setRepeatCount(2);
// ���ö����ظ���ģʽ
rotate.setRepeatMode(Animation.REVERSE);
ScaleAnimation scale = new ScaleAnimation(4f, 0.2f, 4f, 0.2f,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
0.5f);
// ������ʾʱ�䳤��
scale.setDuration(2000);
// �����ظ�����
scale.setRepeatCount(2);
// ���ö����ظ���ģʽ
scale.setRepeatMode(Animation.REVERSE);
Animation alpha = new AlphaAnimation(1f, 0.1f);
// ������ʾʱ�䳤��
alpha.setDuration(2000);
// �����ظ�����
alpha.setRepeatCount(2);
// ���ö����ظ���ģʽ
alpha.setRepeatMode(Animation.REVERSE);
set.addAnimation(tras);
set.addAnimation(alpha);
set.addAnimation(rotate);
set.addAnimation(scale);
// ��ImageView�ϲ��Ŷ���
iv.startAnimation(set);
}