Android动画(Animations)

Androidanimation

动画类型
Android
animation 由四种类型组成

XML

alpha

渐变透明度动画效果

scale

渐变尺寸伸缩动画效果

translate

画面转换位置移动动画效果

rotate

画面转移旋转动画效果

Java代码中

AlphaAnimation

渐变透明度动画效果

ScaleAnimation

渐变尺寸伸缩动画效果

TranslateAnimation

画面转换位置移动动画效果

RotateAnimation

画面转移旋转动画效果

1、main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
 
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >
        <Button
            android:id="@+id/rotateButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="旋转" />
        <Button
            android:id="@+id/scaleButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="缩放" />
        <Button
            android:id="@+id/alphaButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="淡入淡出" />
        <Button
            android:id="@+id/translateButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="移动" />
    </LinearLayout>
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >
        <ImageView
            android:id="@+id/image"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:src="@drawable/an" />
</LinearLayout>
</LinearLayout>


2、.java文件

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.RotateAnimation;
import android.view.animation.ScaleAnimation;
import android.view.animation.TranslateAnimation;
import android.widget.Button;
import android.widget.ImageView;
public class Animation1Activity extends Activity{
       private Button rotateButton = null;
       private Button scaleButton = null;
       private Button alphaButton = null;
       private Button translateButton = null;
       private ImageView mImageView = null;
       private Animation Alpha;
       private Animation Scale;
       private Animation Translate;
       private AnimationRotate;    
       @Override
    public void onCreate(BundlesavedInstanceState) {
        super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
       
            rotateButton =(Button)findViewById(R.id.rotateButton);
            scaleButton =(Button)findViewById(R.id.scaleButton);
            alphaButton =(Button)findViewById(R.id.alphaButton);
            translateButton =(Button)findViewById(R.id.translateButton);
            mImageView = (ImageView)findViewById(R.id.image);
     
           rotateButton.setOnClickListener(newRotateButtonListener());
           scaleButton.setOnClickListener(newScaleButtonListener());
           alphaButton.setOnClickListener(newAlphaButtonListener());
           translateButton.setOnClickListener(
            new TranslateButtonListener());
       }
      class AlphaButtonListener implementsOnClickListener{
            public void onClick(Viewv) {
                        Alpha=animationUtils.loadAnimation(this,R.anim.alpha_action);
                        mImageView.startAnimation(Alpha);
                  }
         }
      class RotateButtonListener implementsOnClickListener{
              public void onClick(Viewv) {
        
                        Rotate = AnimationUtils.loadAnimation(this,R.anim.rotate_action);
                        mImageView.startAnimation(Rotate);
    }
      class ScaleButtonListener implementsOnClickListener{
              public void onClick(Viewv) {
                           Scale =AnimationUtils.loadAnimation(this,R.anim.scale_action);
                           mImageView.startAnimation(Scale);
    }
    class TranslateButtonListener implementsOnClickListener{
              public void onClick(Viewv) {
                             Translate =AnimationUtils.loadAnimation(this,R.anim.translate_action);
                             mImageView.startAnimation(Translate);      
           }
        }
}


1: alpha_action.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"
        />     
</set>
2:rotate_action.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<rotate
        android:interpolator="@android:anim/accelerate_decelerate_interpolator"
        android:fromDegrees="0"
        android:toDegrees="+350"
        android:pivotX="50%"
        android:pivotY="50%"    
        android:duration="3000"/>
</set>
3: scale_action.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
   <scale
          android:interpolator="@android:anim/accelerate_decelerate_interpolator"
          android:fromXScale="0.0"
          android:toXScale="1.4"
          android:fromYScale="0.0"
          android:toYScale="1.4"
          android:pivotX="50%"
          android:pivotY="50%"
          android:fillAfter="false"
          android:duration="700"/>
</set>
 
4: translate_action.xml
 <?xml version="1.0" encoding="utf-8"?>
 <set xmlns:android="http://schemas.android.com/apk/res/android">
 <translate
      android:fromXDelta="30"
      android:toXDelta="-80"
      android:fromYDelta="30"
      android:toYDelta="300"
      android:duration="2000"/>
</set>


下载地址 :http://download.csdn.net/detail/dickyqie/9558580



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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值