- 浏览: 20948 次
最新评论
Animations 可分为两大类:
一 Tweened Animations,该类Animations提供了旋转,移动,伸展,和淡入淡出等效果
二 Frame-by-Frame Animations ,该类Animations 可以创建一个Drawable序列,这些Drawable可能按照指定的时间一个一个的显示,类似于电影.
Tweened Animations 有这4种分类
1 Alpha 淡入淡出
2 Rotate 旋转
3 Scale 缩放
4 Translate 移动
使用Tweened Animations 的步骤
1. 创建一个Animations 对象
2. 根据需要创建相应的Animation对象
3. 按照需求,为Animation 对象设置相应的数据
4. 将Animation对象添加到AnimationSet对象当中
5. 使用控件对象开始执行AnimationSet
各种Animation 的主要属性
Animation type | attributes | valid values
Alpha fromAlpha/toAlpha Float from 0 to 1
Scale fromXScale/toXScale Float from 0 to 1
fromYScale/toYScale Float from 0 to 1
pivotX/pivotY String of the percentage of graphic
width/height from 0% to 100%
Translate fromX/to X Float from 0 to 1
from Y/to Y Float from 0 to 1
Rotate fromDegrees/toDegrees Float from 0 to 360
pivotX/pivotY String of the percentage of graphic
width/height from 0% to 100%
---------------------------
layout布局文件mian.xml文件
activity文件:
Tween Animations 的通用属性
1. setDuration(long durationMills) 设置动画持续时间(单位:毫秒)
2. setFillAfter(boolean fillAfter) 如果fillAfter为true,表示动画执行后,控件将停留在执行结束的状态
3. setFillBefore(boolean fillBefore) 如果fillBefore 的值为true,表示动画执行后,控件将回到动画执行之前的状态
4. setStartOffSet(long startOffSet) 设置动画执行之前的等待时间
5. setRepeatCount(int count) 设置动画重复执行的次数
--------------------
下面再介绍Animations 另一种使用方法
1. 在res文件夹下面新建一个名为anim的文件夹;
2. 创建xml文件,并首先加入set标签,改标签如下:
<set xmlns:android=http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/acccelerate_interpolator" >
</set>
3. 在该标签当中加入rotate,alpha,scale,translate标签
4. 在代码当中使用AnimationUtils当中装载xml文件,并生成 Animation 对象
在rotate.xml文件中
android:pivotX的值共有三种设置方法:
1. android:pivotX="50" 使用绝对位置定位
2. android:pivotX="50%" 使用相对于控件本身定位
3. android:pivotX="50%p" 使用相对于控件的父控件定位
一 Tweened Animations,该类Animations提供了旋转,移动,伸展,和淡入淡出等效果
二 Frame-by-Frame Animations ,该类Animations 可以创建一个Drawable序列,这些Drawable可能按照指定的时间一个一个的显示,类似于电影.
Tweened Animations 有这4种分类
1 Alpha 淡入淡出
2 Rotate 旋转
3 Scale 缩放
4 Translate 移动
使用Tweened Animations 的步骤
1. 创建一个Animations 对象
2. 根据需要创建相应的Animation对象
3. 按照需求,为Animation 对象设置相应的数据
4. 将Animation对象添加到AnimationSet对象当中
5. 使用控件对象开始执行AnimationSet
各种Animation 的主要属性
Animation type | attributes | valid values
Alpha fromAlpha/toAlpha Float from 0 to 1
Scale fromXScale/toXScale Float from 0 to 1
fromYScale/toYScale Float from 0 to 1
pivotX/pivotY String of the percentage of graphic
width/height from 0% to 100%
Translate fromX/to X Float from 0 to 1
from Y/to Y Float from 0 to 1
Rotate fromDegrees/toDegrees Float from 0 to 360
pivotX/pivotY String of the percentage of graphic
width/height from 0% to 100%
---------------------------
layout布局文件mian.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" /> <ImageView android:id="@+id/imageViewId" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/icon" /> <Button android:id="@+id/alphaID" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="淡入淡出效果" /> <Button android:id="@+id/scaleID" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="缩放效果" /> <Button android:id="@+id/rotateID" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="旋转效果" /> <Button android:id="@+id/translateID" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="移动效果" /> </LinearLayout>
activity文件:
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 TestAnimation01Activity extends Activity { /** Called when the activity is first created. */ private ImageView imageView = null; private Button alphaButton = null; private Button scaleButton = null; private Button rotateButton = null; private Button translateButton = null; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); imageView = (ImageView)findViewById(R.id.imageViewId); alphaButton = (Button)findViewById(R.id.alphaID); alphaButton.setOnClickListener(new AlphaButtonListener()); scaleButton = (Button)findViewById(R.id.scaleID); scaleButton.setOnClickListener(new ScaleButtonListener()); rotateButton = (Button)findViewById(R.id.rotateID); rotateButton.setOnClickListener(new RotateButtonListener()); translateButton = (Button)findViewById(R.id.translateID); translateButton.setOnClickListener(new TranslateButtonListener()); } private class AlphaButtonListener implements OnClickListener { @Override public void onClick(View v) { // TODO Auto-generated method stub AnimationSet animationSet = new AnimationSet(true); AlphaAnimation alpha = new AlphaAnimation(1,0); alpha.setDuration(1000); animationSet.addAnimation(alpha); imageView.startAnimation(animationSet); } } private class ScaleButtonListener implements OnClickListener { @Override public void onClick(View v) { // TODO Auto-generated method stub AnimationSet animationSet = new AnimationSet(true); ScaleAnimation scale = new ScaleAnimation(1,0.1f,1,0.1f,Animation.RELATIVE_TO_SELF,05f,Animation.RELATIVE_TO_SELF,0.5f); scale.setDuration(2000); animationSet.addAnimation(scale); imageView.startAnimation(scale); } } private class RotateButtonListener implements OnClickListener { @Override public void onClick(View v) { // TODO Auto-generated method stub AnimationSet animationSet = new AnimationSet(true); RotateAnimation rotate = new RotateAnimation(0,360,Animation.RELATIVE_TO_PARENT,1f,Animation.RELATIVE_TO_PARENT,0f); rotate.setDuration(5000); animationSet.addAnimation(rotate); imageView.startAnimation(animationSet); } } private class TranslateButtonListener implements OnClickListener { @Override public void onClick(View v) { // TODO Auto-generated method stub AnimationSet animationSet = new AnimationSet(true); TranslateAnimation translate = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF, 0.5f); translate.setDuration(2000); animationSet.addAnimation(translate); imageView.startAnimation(animationSet); } } }
Tween Animations 的通用属性
1. setDuration(long durationMills) 设置动画持续时间(单位:毫秒)
2. setFillAfter(boolean fillAfter) 如果fillAfter为true,表示动画执行后,控件将停留在执行结束的状态
3. setFillBefore(boolean fillBefore) 如果fillBefore 的值为true,表示动画执行后,控件将回到动画执行之前的状态
4. setStartOffSet(long startOffSet) 设置动画执行之前的等待时间
5. setRepeatCount(int count) 设置动画重复执行的次数
--------------------
下面再介绍Animations 另一种使用方法
1. 在res文件夹下面新建一个名为anim的文件夹;
2. 创建xml文件,并首先加入set标签,改标签如下:
<set xmlns:android=http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/acccelerate_interpolator" >
</set>
3. 在该标签当中加入rotate,alpha,scale,translate标签
4. 在代码当中使用AnimationUtils当中装载xml文件,并生成 Animation 对象
在rotate.xml文件中
android:pivotX的值共有三种设置方法:
1. android:pivotX="50" 使用绝对位置定位
2. android:pivotX="50%" 使用相对于控件本身定位
3. android:pivotX="50%p" 使用相对于控件的父控件定位
发表评论
-
SQLite数据库
2011-10-21 11:12 9911。从www.sqlite.org下载SQLite 3.3.4 ... -
android中的有道词典实例
2011-10-19 22:51 8961、布局文件main.xml <?xml version ... -
mars老师的googleMap示例(二)
2011-10-15 17:14 844manifest.xml文件 <?xml version ... -
mars老师的googleMap(一)
2011-10-15 10:43 789一、申请 Apikey Apikey Apikey Apike ... -
Intent在android中的几种用法
2011-10-14 09:26 753如果是从BroadcastReceiver 启动一个新的Act ... -
基于Service与ContentProvider的音乐播放实例
2011-10-13 23:37 726Android的核心也就是Activi ... -
android之用户定位(一)
2011-10-13 19:53 16651、User Location 能做什么 1) 获取用户的位置 ... -
android之蓝牙操作(二)
2011-10-13 18:43 12711、修改本蓝牙设备的可见性 2、扫描周围可用蓝牙设备 步骤: ... -
android之蓝牙操作(一)
2011-10-13 16:35 1206与蓝牙相关的API 1、BluetoothAdapter ... -
Android学习之JSON数据解析
2011-10-12 13:30 675在Android应用开发中,常用的数据交换格式有XML和JSO ... -
android中的JSON解析
2011-10-12 10:17 8831 。 什么是JSON 就是现在网络上比较流行 ... -
Animations的使用(六)
2011-10-11 17:44 1106LayoutAnimationController的使用方法( ... -
Animations的使用(五)
2011-10-11 17:41 7021 AnimationSet的使用方法 什么是Animat ... -
Animations使用 (四)
2011-10-11 17:36 546Animations的第二种使用方法(第一种见1) 步骤: ... -
android面试
2011-10-10 21:12 762为什么要用ContentProvider?它和sql的实现上有 ... -
android中的animations的用法(三)
2011-10-10 21:07 690一 LayoutAnimationController ... -
android中的animations的用法(二)
2011-10-10 20:59 766一 AnimationSet 的用法 二 Interpol ...
相关推荐
主要介绍了Android开发之Animations动画用法,结合实例形式详细分析了Animations动画的类型、组成、模式及对应的使用技巧,需要的朋友可以参考下
使用变形动画将视图转换为另一个视图。 您还可以在两个活动或片段之间进行变形。 这是非常好的外观效果,将帮助您的用户更好地了解屏幕上发生的更改。 TransformationLayout使用...
在此处获得此库的良好概述: : 一体化要在您的项目中使用AdditiveAnimator ,请在build.gradle添加以下几行: dependencies { compile 'at.wirecube:additive_animations:1.9.0'}...repositories { jcenter()}快速...
Animations是一个实现android UI界面动画效果的API,Animations提供了一系列的动画效果,可以进行旋转、缩放、淡入淡出等,这些效果可以应用在绝大多数的控件中。 二、Animations的分类 Animations从总体上可以分为...
这里介绍一下SVGAPlayer-Android用法。 想知道导出用法吗? 请点击。 通过Gradle安装 我们在JitPack上托管一个AAR文件,您需要添加JitPack.io回购build.gradle allprojects { repositories { ... maven { url '...
用法通过Gradle添加RxAnimation库:实现'com.mikhaellopez:rxanimation:1.0.0'KOTLIN A这是一个Android库,使使用Rx对Android上的视图进行动画处理的简单方法。 用法通过Gradle添加RxAnimation库:实现'...
PM> Install-Package Xam.Animations用法该软件包将AnimateAsync扩展方法添加到UIView (iOS) / NSView (macOS) / View (Android) / UIElement (Windows) 。 用IAnimation开始动画。 await view . ...
设置Android Studio / Gradle在存储库末尾的root build.gradle中添加以下依赖项:allprojects {存储库{// ... maven {url ='https://jitpack.io'}}}添加依赖项:依赖项{实现'...
适用于Android的Shimmer是Android库,它提供了一种向您的Android应用程序中的任何视图添加闪烁效果的简便方法。 它用作不显眼的加载指示器,最初是为Android的Face Shimmer开发的。Shimmer是一个Android库,它提供了...
一个React Native组件,向子组件添加简单的进入,退出和寻求注意的动画。 适用于iOS和Android。 例子 安装 npm install react-native-simple-animations --save 用法 导入SimpleAnimation组件: import { Simple...
TypeWriterView一个简单的Android库,用于类似打字机的效果特征: 对textview的内容进行动画处理,就好像它是由TypeWriter键入的一样设置动画文字的显示持续时间设置TypeWriter声音效果(有声或无声) 设置打字动画...
Bubble-Picker在dribbble上检查该项目阅读我们如何在中等要求上执行Android SDK 16+用法添加到您的根build.gradle:allprojects {存储库{... maven {url“ Bubble-Picker在dribbble上检查该项目阅读如何我们是在中等...
一个 android 项目,展示了您可以在活动之间使用的一些转换 #一体化 将 anim 文件夹添加到您的 Android 项目的 res 文件夹中 导入 ActivityAnimator 类 在startActivity(Intent i)方法之后立即调用new ...
EasyAndroidAnimations Easy Android Animations是一个动画库,旨在Easy Android Animations ,提供50+内置动画,它允许您使用一两行代码在应用程序中引入许多复杂的动画效果。示范影片 用法:包括在您的项目中您...
Bounceview-Android 可自定义的跳动动画,用于任何视图更新 入门 在您的build.gradle中 dependencies { implementation ' hari.bounceview:bounceview:0.2.0 ' } 用法 将动画添加到任何视图中,如下所示: Button...
用Kotlin编写的用于Android的简单且出色的动画库AnimationX用Kotlin编写的用于Android的简单而出色的动画库屏幕快照文档安装步骤1.将JitPack存储库添加到构建文件中的所有项目{存储库{maven {url'...
Xplosion Xplosion是一个分支,已转换为Kotlin,并已更新为最新版本的Android :grinning_face_with_smiling_eyes: Twitter喜欢任何视图的动画 :beating_heart:用法步骤1.确保在根gradle文件mavenCentral()添加为依赖...
使用 Web Animations 为theme-color元标记设置动画的助手。 或(Chrome 36+,目前仅适用于 Android)。 安装 可选安装 Bower: $ bower install rainbows 需要或 。 用法 < script src =" bower_components/...
Xamarin.Android.AVLoadingIndicatorView 这是的Xamarin Android绑定。 AVLoadingIndicatorView是适用于Android的漂亮加载动画的集合。 演示版 用法 (有关详细的工作示例,请参见项目) 步骤1 安装NuGet。 第2步...