`
rayln
  • 浏览: 437186 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

Animation动画效果二(推荐)

 
阅读更多
Interpolator定义动画变化
AccelerateDecelerateInterpolator动画开始和结束的地方速率改变比较慢, 中间加速
AccelerateInterpolator动画开始的地方速率改变比较慢, 然后开始加速
CycleInterpolator动画循环播放特定的次数, 速率改变沿着正玄曲线
DecelerateInterpolator动画开始的地发光速率改变比较慢, 然后开始减速
LinearInterpolator在动画以均匀的速率改变

比如下面例子的xml声明部分android:interpolator="@android:anim/accelerate_interpolator", 如果后面再加上android:shareInterpolator="true", 则意味set中所有动画效果将同样使用AccelerateDecelerateInterpolator, 如果为false. 则需要在每个动画中定义这个Interpolator. 例如:
<alpha andorid:interpolator="@android:anim/accelerate_interpolator"/>


首先在/res/文件夹下面新建anim文件夹, 新建一个xml文件存放animation效果
例如/res/anim/alph.xml

例子:
/res/anim/alph.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_decelerate_interpolator">
    <alpha android:fromAlpha="1" android:toAlpha="0" android:duration="1000"/>
</set>


/res/anim/rotate.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_decelerate_interpolator">
	<!-- android:pivotX="50" 表示绝对定位
		 android:pivotX="50%" 表示相对控件本身的定位
		 android:pivotX="50%p" 表示相对父控件的定位
	 -->
    <rotate android:fromDegrees="0" android:toDegrees="+350" android:pivotX="50%" android:pivotY="50%" android:duration="3000"/>
</set>


/res/anim/sacle.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_decelerate_interpolator">
	<!-- android:pivotX="50" 表示绝对定位
		 android:pivotX="50%" 表示相对控件本身的定位
		 android:pivotX="50%p" 表示相对父控件的定位
	 -->
    <scale android:fromXScale="1" android:toXScale="0" android:fromYScale="1" android:toYScale="0" android:pivotX="50%" android:pivotY="50%" android:duration="2000"/>
</set>


/res/anim/translate.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_decelerate_interpolator">
    <translate android:fromXDelta="50%" android:toXDelta="100%" android:fromYDelta="0" android:toYDelta="100%" android:duration="2000"/>
</set>


main.xml
<?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"
    >
	<TextView  
	    android:layout_width="fill_parent" 
	    android:layout_height="wrap_content" 
	    android:text="@string/hello"
	    />
	<LinearLayout android:id="@+id/linearLayout1" android:layout_width="match_parent" android:orientation="vertical" android:layout_height="wrap_content" android:layout_weight="1">
	    <ImageView android:layout_height="wrap_content" android:id="@+id/imageView1" android:layout_width="wrap_content" android:src="@drawable/icon" ></ImageView>
	</LinearLayout>
	<LinearLayout android:layout_height="wrap_content" android:id="@+id/linearLayout2" android:layout_width="match_parent" android:orientation="vertical">
	    <Button android:layout_height="wrap_content" android:layout_width="match_parent" android:id="@+id/button1" android:text="@string/translate" android:onClick="translate"></Button>
	    <Button android:layout_height="wrap_content" android:layout_width="match_parent" android:id="@+id/button3" android:text="@string/alpha" android:onClick="alpha"></Button>
	    <Button android:layout_height="wrap_content" android:layout_width="match_parent" android:id="@+id/button2" android:text="@string/rotate" android:onClick="rotate"></Button>
	    <Button android:layout_height="wrap_content" android:layout_width="match_parent" android:id="@+id/button4" android:text="@string/scale" android:onClick="scale"></Button>
	</LinearLayout>
</LinearLayout>


Animation2Activity.java
package com.cn;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;

public class Animation2Activity extends Activity {
    /** Called when the activity is first created. */
	ImageView iv = null;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        iv = (ImageView)findViewById(R.id.imageView1);
    }
    
    public void translate(View v){
    	Animation animation = AnimationUtils.loadAnimation(this, R.anim.translate);
    	iv.startAnimation(animation);
    }
    public void alpha(View v){
    	Animation animation = AnimationUtils.loadAnimation(this, R.anim.alpha);
    	iv.startAnimation(animation);
    }
    public void rotate(View v){
    	Animation animation = AnimationUtils.loadAnimation(this, R.anim.rotate);
    	iv.startAnimation(animation);
    }
    public void scale(View v){
    	Animation animation = AnimationUtils.loadAnimation(this, R.anim.sacle);
    	iv.startAnimation(animation);
    }
}
分享到:
评论

相关推荐

    iphone用Animation实现动画效果

    在本教程中,我们将深入探讨如何使用`UIView`的`animation`方法来创建简单的上、中、下移动动画效果。这涉及到iOS开发中的基本动画原理,以及如何通过代码控制视图的行为。 首先,我们要理解`UIView`动画的基本概念...

    wpf Animation动画效果演示,包含多个实例

    在本文中,我们将深入探讨WPF(Windows Presentation Foundation)中的动画效果,并通过多个实例来展示其强大功能。WPF Animation是微软.NET Framework的一部分,它为开发者提供了丰富的视觉表现手法,可以实现平滑...

    微信小程序 鲜花订购,animation动画卡片效果 (源码)

    微信小程序 鲜花订购,animation动画卡片效果 (源码)微信小程序 鲜花订购,animation动画卡片效果 (源码)微信小程序 鲜花订购,animation动画卡片效果 (源码)微信小程序 鲜花订购,animation动画卡片效果 (源码)微信...

    微信小程序源码 鲜花订购,animation动画卡片效果(学习版)

    微信小程序源码 鲜花订购,animation动画卡片效果(学习版)微信小程序源码 鲜花订购,animation动画卡片效果(学习版)微信小程序源码 鲜花订购,animation动画卡片效果(学习版)微信小程序源码 鲜花订购,animation动画...

    微信小程序源码(含截图)鲜花订购,animation动画卡片效果

    微信小程序源码(含截图)鲜花订购,animation动画卡片效果微信小程序源码(含截图)鲜花订购,animation动画卡片效果微信小程序源码(含截图)鲜花订购,animation动画卡片效果微信小程序源码(含截图)鲜花订购,...

    微信小程序实现animation动画

    微信小程序实现animation动画,具体内容如下 1. 创建动画实例 wx.createAnimation(OBJECT) 创建一个动画实例animation。调用实例的方法来描述动画。最后通过动画实例的export方法导出动画数据传递给组件的...

    动画包_animation动画效果_源码

    "动画包_animation动画效果_源码"这个资源包,显然是为了帮助开发者理解和实现各种动画效果而准备的。它可能包含了一系列使用了Android内置的animation库编写的示例代码。下面将详细讨论Android中的动画技术及其重要...

    animation动画效果

    总结,OC的动画效果是通过Core Animation和UIKit提供的API实现的,涵盖了从简单到复杂的各种动画需求。理解这些基础知识和技巧,开发者能够创造出富有吸引力和交互性的iOS应用。在实际开发中,根据项目需求灵活运用...

    css3弹力球动画animation属性制作3D弹力球弹跳动画效果

    这个动画效果不仅增强了用户界面的视觉吸引力,还能提供更好的交互体验。接下来,我们将深入探讨如何利用CSS3的`animation`属性来制作这样一个3D弹力球动画。 首先,我们需要理解`animation`属性的基本结构。它是一...

    Animation动画实例源代码

    本资源“Animation动画实例源代码”提供了一系列详细实例,帮助开发者深入了解和实践Android中的动画技术。这些实例适用于ADT(Android Development Toolkit)版本10及ECLIPSE JUNO开发环境。 Android动画主要包括...

    微信小程序——鲜花订购,animation动画卡片效果(截图+源码).zip

    微信小程序——鲜花订购,animation动画卡片效果(截图+源码).zip 微信小程序——鲜花订购,animation动画卡片效果(截图+源码).zip v微信小程序——鲜花订购,animation动画卡片效果(截图+源码).zip 微信小程序...

    frameAnimation动画效果

    帧动画(Frame Animation)是Android系统提供的一种基本的动画机制,它通过连续播放一系列静态图像来创造出动态的效果,类似于我们小时候看的翻页动画书。在手机软件开发中,帧动画常用于创建简单的过渡效果、加载...

    使用animation翻页动画效果

    本主题将深入探讨如何使用`animation`类动画效果来实现手机页面的翻页效果,这是一种常见的视觉过渡手段,使得用户在浏览内容时感觉更加自然和舒适。 一、动画基础 在计算机图形学中,动画是通过连续展示一系列...

    android Animation动画实现loading效果

    除了原生的Android动画,还有许多第三方库提供丰富的加载动画效果,如`android-Universal-Image-Loader`、`Glide`、`Picasso`等图片加载库均支持添加自定义加载动画。此外,还有专门为加载效果设计的库,如`...

    Core Animation动画例子

    通过这个“Core Animation动画例子”压缩包,你可以学习到如何在实践中运用上述知识点,创建出流畅、精致的iOS应用动画效果。记住,实践是最好的老师,深入研究并动手尝试这些示例,将有助于你更好地掌握Core ...

    Animation动画的解析与自定义Animation动画

    本篇文章将深入解析Android中的动画系统,并探讨如何自定义Animation动画。 首先,Android提供了两种主要的动画机制:属性动画(Property Animation)和视图动画(View Animation)。属性动画是在Android 3.0(API ...

    LoadingAnimation 动画 加载动画

    - **固定帧动画**:由一系列静态图像按顺序播放构成,常用于创建简单的连续动画效果。在Android中,这可以通过`AnimationDrawable`类实现。 2. **AnimationTest**: - 这个文件名可能对应的是一个测试项目或者一...

    Animation动画效果

    "Animation动画效果"这个主题涵盖了多种技术和概念,下面将对其进行详细阐述。 1. **基本动画原理**:动画的基本原理是通过连续显示一系列微小变化的静态图像来创建动态视觉效果。这些图像通常被称为帧,而帧率(如...

    Android Tween Animation动画效果详解

    Android Tween Animation动画的使用demo,以及自定义动画,原理解析,相关博客: http://blog.csdn.net/w18756901575/article/details/53081551

    html5+css3 animation制作各种页面过渡切换动画效果

    在本文中,我们将深入探讨如何利用HTML5和CSS3的animation属性来制作各种页面过渡和切换动画效果。 首先,HTML5的引入极大地扩展了网页的语义化元素,如`&lt;article&gt;`、`&lt;section&gt;`、`&lt;header&gt;`和`&lt;footer&gt;`等,这些...

Global site tag (gtag.js) - Google Analytics