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

     

     

  • 相关阅读:
    MDX Step by Step 读书笔记(六) Building Complex Sets (复杂集合的处理) Filtering Sets
    在 Visual Studio 2012 开发 SSIS,SSAS,SSRS BI 项目
    微软BI 之SSIS 系列 在 SSIS 中读取 SharePoint List
    MDX Step by Step 读书笔记(五) Working with Expressions (MDX 表达式) Infinite Recursion 和 SOLVE_ORDER 原理解析
    MDX Step by Step 读书笔记(五) Working with Expressions (MDX 表达式)
    使用 SQL Server 2012 Analysis Services Tabular Mode 表格建模 图文教程
    MDX Step by Step 读书笔记(四) Working with Sets (使用集合) Limiting Set and AutoExists
    SQL Server 2012 Analysis Services Tabular Model 读书笔记
    Microsoft SQL Server 2008 MDX Step by Step 学习笔记连载目录
    2011新的开始,介绍一下AgileEAS.NET平台在新的一年中的发展方向
  • 原文地址:https://www.cnblogs.com/zhangqie/p/6039342.html
Copyright © 2011-2022 走看看