好久没做实验工作总结了,还是得克服懒惰的思想做一下实验记录。
好记性不如烂笔头——转同学名言。

今天记录一下我学Android 的动画设计实验,处理的对象是一个文本字符串。

Ready, Go!

Step1 界面布局:依然是layout/main.xml
xml version ="1.0" encoding ="utf-8" ?>
< RelativeLayout xmlns:android ="http://schemas.android.com/apk/res/android"
         android:orientation ="vertical"
         android:layout_width ="fill_parent"
         android:layout_height ="fill_parent"
         >
   < TextView    
         android:layout_width ="wrap_content"
         android:layout_height ="wrap_content"
         android:text ="@string/hello"
         android:id ="@+id/text"
         android:layout_centerHorizontal ="true"
         android:layout_centerVertical ="true"
         />
   < Button
   android:layout_width ="fill_parent"
   android:layout_height ="wrap_content"
   android:id ="@+id/rotate"
   android:text ="Rotate"
   android:layout_alignParentBottom ="true"
   >
   Button >
RelativeLayout >

加入了一个文本视图(屏幕居中)和一个控制按钮(放置在屏幕底部)

另外一个重要的工作时加入一个创建动画属性配置文件,从网上搞到一个牛人的配置文件,很详细,贴一下 http://blog.csdn.net/zhqingyun163/archive/2009/11/05/4770068.aspx。
(这里的工作是创建动画配置文件ani_rotate.xml,创建位位置:res文件夹下创建anim/ani_rotate.xml)

xml version ="1.0" encoding ="utf-8" ?>
< set xmlns:android ="http://schemas.android.com/apk/res/android" >
            
            
         < alpha    
                 android:fromAlpha ="0.1"    
                 android:toAlpha ="1.0"    
                 android:duration ="3000"    
         />    
                    
            
         < scale    
                 android:interpolator ="@android:anim/accelerate_decelerate_interpolator"    
                 android:repeatCount ="1"    
                    
                 android:fromXScale ="0.5"    
                 android:fromYScale ="0.5"    
                 android:toXScale ="1.4"                
                 android:toYScale ="1.4"    
                 android:pivotX ="50%"    
                 android:pivotY ="50%"    
                 android:fillAfter ="false"    
                 android:duration ="3000"    
                    
         />    
            
            
         < translate    
                 android:repeatCount ="2"    
                 android:fromXDelta ="-30"    
                 android:fromYDelta ="-30"    
                 android:toXDelta ="-80"                
                 android:toYDelta ="200"    
                 android:duration ="3000"    
         />    
            
         < rotate    
                 android:interpolator ="@android:anim/accelerate_interpolator"    
                 android:repeatCount ="2"    
                 android:fromDegrees ="0"    
                 android:toDegrees ="+270"    
                 android:pivotX ="50%"    
                 android:pivotY ="50%"    
                 android:duration ="3000"    
         />
set >

Step 2 Java控制代码:
package com.penguin7.animationtest;

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;

public class AnimationTest extends Activity implements OnClickListener{
   private Button bntRotate = null;

   /** Called when the activity is first created. */
  @Override
   public void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
     //获取按键资源
    bntRotate = (Button) findViewById(R.id.rotate);
     //启动按键监听
    bntRotate.setOnClickListener( this);
  }
  
  @Override
   public void onClick(View v){
     //定义动画属性
    Animation ani = AnimationUtils.loadAnimation( this, R.anim.ani_rotate);
     //启动动画
    findViewById(R.id.text).startAnimation(ani);
  }

}

Step 3 看看效果:
启动画面:
动画截屏: