Android35_Animations应用(三)

Android35_Animations使用(三)?AnimationSet animationSet new AnimationSet(true)AlphaAnimation alph

Android35_Animations使用(三)

?

AnimationSet animationSet = new AnimationSet(true);AlphaAnimation alphaAnimation = new AlphaAnimation(1, 0);RotateAnimation rotateAnimation = new RotateAnimation(0, 360,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f);rotateAnimation.setDuration(1000);animationSet.addAnimation(rotateAnimation); animationSet.addAnimation(alphaAnimation);image.startAnimation(animationSet);

?

二、Interpolator的具体使用方法

? ? ? ?Interpolator定义了动画变化的速率,在Animations框架当中定义了一下几种Interpolator

android:interpolator="@android:anim/accelerate_interpolator"

如果一个set中包含了两种动画效果,要想这两种动画效果共享一个interpolator,可以在set标签上添加:

android:shareInterpolator="true"
如果不想共享一个interpolator,则可以在alpha等标签上添加。

另以上方法是在xml上处理interpolator,如果是在代码上设置共享一个interpolator,则可以在AnimationSet设置interpolator,如果不设置共享一个interpolator则可以在alpha等的对象上面设置interpolator:

animationSet.setInterpolator(new AccelerateInterpolator());

?或

alphaAnimation.setInterpolator(new AccelerateInterpolator());

?

?三、Frame-By-FrameAnimations的使用方法

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"><LinearLayout android:orientation="horizontal" android:layout_height="wrap_content" android:layout_width="wrap_content"><Button android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="运动"/></LinearLayout><LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"><ImageView android:id="@+id/image" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true"/></LinearLayout></LinearLayout>?

<?xml version="1.0" encoding="utf-8"?><animation-list xmlns:android="http://schemas.android.com/apk/res/android"android:oneshot="false"><item android:drawable="@drawable/a_01" android:duration="50"/><item android:drawable="@drawable/a_02" android:duration="50"/><item android:drawable="@drawable/a_03" android:duration="50"/><item android:drawable="@drawable/a_04" android:duration="50"/><item android:drawable="@drawable/a_05" android:duration="50"/><item android:drawable="@drawable/a_06" android:duration="50"/></animation-list>?

package com.android.activity;import android.app.Activity;import android.graphics.drawable.AnimationDrawable;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.ImageView;public class AnimationsActivity extends Activity {private Button button = null;private ImageView imageView = null;@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); button = (Button)findViewById(R.id.button); imageView = (ImageView)findViewById(R.id.image); button.setOnClickListener(new ButtonListener()); }class ButtonListener implements OnClickListener{public void onClick(View v) {imageView.setBackgroundResource(R.anim.anim);AnimationDrawable animationDrawable = (AnimationDrawable)imageView.getBackground();animationDrawable.start();}}}?