Android控件动画

圆周轨迹动画:

<span style="font-size:18px;">	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		final ImageView image = (ImageView) this.findViewById(R.id.image);
		Button btn = (Button) this.findViewById(R.id.btn);

		final ValueAnimator animator = ValueAnimator.ofFloat(0, 360);

		animator.setDuration(1500);

		animator.setInterpolator(new LinearInterpolator());

		animator.addUpdateListener(new AnimatorUpdateListener() {

			@Override
			public void onAnimationUpdate(ValueAnimator anim) {

				float i = (Float) anim.getAnimatedValue();
				image.setX(-(1 - i / 360) * 100
						* (float) Math.sin(i * Math.PI / 180));
				image.setY(-(1 - i / 360) * 100
						* (float) Math.cos(i * Math.PI / 180));
				image.setAlpha(i);
				// image.setScaleX(i);
				// image.setScaleY(i);
			}
		});

		btn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {

				// image.startAnimation(rotate);
				animator.cancel();
				animator.start();
			}
		});

	}

}
</span>

2 浮标动画:


<span style="font-size:18px;">package com.example.animation;

import android.animation.TypeEvaluator;
import android.animation.ValueAnimator;
import android.animation.ValueAnimator.AnimatorUpdateListener;
import android.app.Activity;
import android.graphics.PointF;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.CycleInterpolator;
import android.view.animation.LinearInterpolator;
import android.view.animation.RotateAnimation;
import android.view.animation.ScaleAnimation;
import android.widget.Button;
import android.widget.ImageView;

public class MainActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		final ImageView image = (ImageView) this.findViewById(R.id.image);
		final Button btn = (Button) this.findViewById(R.id.btn);

		//加载anim文件 的xml
				 final Animation animation=AnimationUtils.
				 loadAnimation(this, R.anim.tween_animation);
				 animation.setDuration(2000);


		btn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {

				// image.startAnimation(rotate);
				image.startAnimation(animation);
				
			}
		});

	}

}
</span>

<span style="font-size:18px;"><?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >

  <translate  
        android:duration="1000"  
        android:fromXDelta="0"  
        android:fromYDelta="-15"  
        android:repeatCount="infinite"  
        android:toXDelta="0"  
        android:toYDelta="20" />  
  
    <alpha  
        android:duration="1000"  
        android:fromAlpha="1.0"  
        android:repeatCount="infinite"  
        android:toAlpha="0.3" />  


</set></span>

3 组合动画 旋转

<span style="font-size:18px;"><set xmlns:android="http://schemas.android.com/apk/res/android" >  
  
    <scale  
        android:duration="800"  
        android:fillAfter="false"  
        android:fromXScale="0.0"  
        android:fromYScale="0.0"  
        android:interpolator="@android:anim/accelerate_decelerate_interpolator"  
        android:pivotX="50%"  
        android:pivotY="50%"  
        android:toXScale="1.2"  
        android:toYScale="1.2" />  
  
    <rotate  
        android:duration="3000"  
        android:fromDegrees="0"  
        android:pivotX="50%"  
        android:pivotY="50%"  
        android:repeatCount="-1"  
        android:toDegrees="359.0" />  
  
</set> </span>
4 摇摆动画

<span style="font-size:18px;">	int pivot = Animation.RELATIVE_TO_SELF;  
        CycleInterpolator interpolator = new CycleInterpolator(3.0f);  
        final RotateAnimation animation = new RotateAnimation(0, 10, pivot,  
                0.47f, pivot, 0.05f);  
        animation.setStartOffset(500);  
        animation.setDuration(3000);  
        animation.setRepeatCount(1);// Animation.INFINITE   
        animation.setInterpolator(interpolator);  </span>

5 一个角度摇摆

RELATIVE_TO_PARENT 

<span style="font-size:18px;">int pivot=RELATIVE_TO_PARENT  换成这个参数</span>






  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值