风言枫语  

Android的动画可以是一种动画,也可以多种动画作用于一张图片上,如RotaeAnimation和AlphaAnimation同时放到一个配置文件中

alpha1.xml

 

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/accelerate_interpolator" >

    <alpha
        android:duration="3000"
        android:fromAlpha="1.0"
        android:toAlpha="0.0"
        android:startOffset="500" />
    
    <rotate
        android:duration="3000"
        android:fromDegrees="0"
        android:pivotX="50%"
        android:pivotY="50%"
        android:toDegrees="+360" />

</set>

 


package com.example.animation;

import android.app.Activity;
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.widget.Button;
import android.widget.ImageView;

import com.example.widgetdemo.R;

public class AnimationXmlDemo2 extends Activity{
	private Button alpha = null;
	private ImageView image = null;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.animation_xml2);
		alpha = (Button) findViewById(R.id.alpha);
		image = (ImageView) findViewById(R.id.image);
		alpha.setOnClickListener(new alphaListener());
	}
	
	class alphaListener implements OnClickListener {

		@Override
		public void onClick(View arg0) {
			// TODO Auto-generated method stub
			Animation animation = AnimationUtils.loadAnimation(AnimationXmlDemo2.this, R.anim.alpha1);
			image.startAnimation(animation);
		}

	}
}



点击alpha演示看到的效果是图片一边旋转一边消失

源代码下载

点击打开链接

 

posted on 2013-09-02 18:20  风言枫语  阅读(305)  评论(0)    收藏  举报