zoukankan      html  css  js  c++  java
  • Android动画(Animations)

    动画类型
    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

     

     

  • 相关阅读:
    Spring Cloud 接口契约测试
    看我玩弄千万日志于股掌
    从哲学层面浅谈计算机学习方法论
    一切互联网优势都是效率优势,一切竞争最终都是效率之争
    Arduino--蜂鸣器
    Arduino--光感应模块--模拟输入
    Arduino---按钮
    Arduino--PWM引脚
    Arduino专用绘图软件Fritzing
    点亮LED灯
  • 原文地址:https://www.cnblogs.com/zhangqie/p/6039342.html
Copyright © 2011-2022 走看看