- 浏览: 65970 次
- 性别:
- 来自: Mercury
最新评论
一、Animations介绍
Animations是一个实现android UI界面动画效果的API,Animations提供了一系列的动画效果,可以进行旋转、缩放、淡入淡出等,这些效果可以应用在绝大多数的控件中。
二、Animations的分类
Animations从总体上可以分为两大类:
1.Tweened Animations:该类Animations提供了旋转、移动、伸展和淡出等效果。Alpha——淡入淡出,Scale——缩放效果,Rotate——旋转,Translate——移动效果。
2.Frame-by-frame Animations:这一类Animations可以创建一个Drawable序列,这些Drawable可以按照指定的时间间歇一个一个的显示。
三、Animations的使用方法(代码中使用)
对象之间的关系:
使用TweenedAnimations的步骤:
1.创建一个AnimationSet对象(Animation子类);
2.增加需要创建相应的Animation对象;
3.更加项目的需求,为Animation对象设置相应的数据;
4.将Animatin对象添加到AnimationSet对象当中;
5.使用控件对象开始执行AnimationSet。
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" > <LinearLayout android:orientation="horizontal" android:layout_height="wrap_content" android:layout_width="wrap_content"> <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:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <ImageView android:id="@+id/image" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:src="@drawable/image"/> </LinearLayout> </LinearLayout>
AnimationsActivity.java
package com.android.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 AnimationsActivity extends Activity { private Button rotateButton = null; private Button scaleButton = null; private Button alphaButton = null; private Button translateButton = null; private ImageView image = null; @Override public void onCreate(Bundle savedInstanceState) { 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); image = (ImageView)findViewById(R.id.image); rotateButton.setOnClickListener(new RotateButtonListener()); scaleButton.setOnClickListener(new ScaleButtonListener()); alphaButton.setOnClickListener(new AlphaButtonListener()); translateButton.setOnClickListener( new TranslateButtonListener()); } class AlphaButtonListener implements OnClickListener{ public void onClick(View v) { //创建一个AnimationSet对象,参数为Boolean型, //true表示使用Animation的interpolator,false则是使用自己的 AnimationSet animationSet = new AnimationSet(true); //创建一个AlphaAnimation对象,参数从完全的透明度,到完全的不透明 AlphaAnimation alphaAnimation = new AlphaAnimation(1, 0); //设置动画执行的时间 alphaAnimation.setDuration(500); //将alphaAnimation对象添加到AnimationSet当中 animationSet.addAnimation(alphaAnimation); //使用ImageView的startAnimation方法执行动画 image.startAnimation(animationSet); } } class RotateButtonListener implements OnClickListener{ public void onClick(View v) { AnimationSet animationSet = new AnimationSet(true); //参数1:从哪个旋转角度开始 //参数2:转到什么角度 //后4个参数用于设置围绕着旋转的圆的圆心在哪里 //参数3:确定x轴坐标的类型,有ABSOLUT绝对坐标、RELATIVE_TO_SELF相对于自身坐标、RELATIVE_TO_PARENT相对于父控件的坐标 //参数4:x轴的值,0.5f表明是以自身这个控件的一半长度为x轴 //参数5:确定y轴坐标的类型 //参数6:y轴的值,0.5f表明是以自身这个控件的一半长度为x轴 RotateAnimation rotateAnimation = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF,0.5f, Animation.RELATIVE_TO_SELF,0.5f); rotateAnimation.setDuration(1000); animationSet.addAnimation(rotateAnimation); image.startAnimation(animationSet); } } class ScaleButtonListener implements OnClickListener{ public void onClick(View v) { AnimationSet animationSet = new AnimationSet(true); //参数1:x轴的初始值 //参数2:x轴收缩后的值 //参数3:y轴的初始值 //参数4:y轴收缩后的值 //参数5:确定x轴坐标的类型 //参数6:x轴的值,0.5f表明是以自身这个控件的一半长度为x轴 //参数7:确定y轴坐标的类型 //参数8:y轴的值,0.5f表明是以自身这个控件的一半长度为x轴 ScaleAnimation scaleAnimation = new ScaleAnimation( 0, 0.1f,0,0.1f, Animation.RELATIVE_TO_SELF,0.5f, Animation.RELATIVE_TO_SELF,0.5f); scaleAnimation.setDuration(1000); animationSet.addAnimation(scaleAnimation); image.startAnimation(animationSet); } } class TranslateButtonListener implements OnClickListener{ public void onClick(View v) { AnimationSet animationSet = new AnimationSet(true); //参数1~2:x轴的开始位置 //参数3~4:y轴的开始位置 //参数5~6:x轴的结束位置 //参数7~8:x轴的结束位置 TranslateAnimation translateAnimation = new TranslateAnimation( Animation.RELATIVE_TO_SELF,0f, Animation.RELATIVE_TO_SELF,0.5f, Animation.RELATIVE_TO_SELF,0f, Animation.RELATIVE_TO_SELF,0.5f); translateAnimation.setDuration(1000); animationSet.addAnimation(translateAnimation); image.startAnimation(animationSet); } } }
运行结果:
发表评论
文章已被作者锁定,不允许评论。
-
Android40_Dialog
2011-11-14 00:11 2942Dialog是Android常用的对话框控件。AlertDia ... -
Android39_Clock和TimePicker
2011-11-14 00:08 2317一、AnalogClock和DigitalClock ... -
Android38_ImageView和Gallery
2011-11-14 00:07 3557一、ImageView使用方法 ImageVi ... -
Android37_JSON数据解析
2011-11-08 00:14 2303一、JSON介绍 JSON(JavaSc ... -
Android36_Animations使用(四)
2011-11-08 00:14 3379一、LayoutAnimationsContrlller ... -
Android35_Animations使用(三)
2011-11-08 00:13 2609一、AnimationSet的具体使用方法 ... -
Android34_Animations使用(二)
2011-11-08 00:12 1919在代码中使用Animations可以很方便的调试、运行 ... -
Android31_AppWidget使用(二)
2011-11-05 00:09 2462一、PendingIntent介绍 PendingIn ... -
Android30_AppWidget使用(一)
2011-11-05 00:08 2226一、App Widget定义 App ... -
Android32_Notification用法
2011-11-05 00:09 1840Android系统的状态栏(Status Bar)中有一 ... -
Android29_SeekBar和RatingBar
2011-11-02 23:21 2065一、使用SeekBar步骤: SeekB ... -
Android28_ExpandableListActivity
2011-11-02 23:21 1455ExpandableListActivity就是可扩展的 ... -
Android27_AutoCompleteTextView
2011-11-02 23:21 1029一、创建AutoCompleteTextView ... -
Android26_DatePicker
2011-11-02 23:20 1746一、DatePicker和DatePickerDialo ... -
Android25_Spinner使用方法
2011-11-02 23:20 2772一、创建Spinner的步骤 1.在布局 ... -
Android24_Service初步
2011-10-18 22:27 965一、Service概念 ... -
Android23_Socket编程
2011-10-18 22:19 1467一、什么是Socket Socket是基 ... -
Android22_WIFI网络操作
2011-10-18 22:12 1651一、什么是WIFI WIFI就是一种无线 ... -
Android21_广播机制(二)
2011-10-18 22:00 964一、注册BroadcastReceiver的方法 ... -
Android20_广播机制(一)
2011-10-18 21:48 1047一、Android广播机制介绍 Android:操作系统 ...
相关推荐
Android-android_additive_animations.zip,Android附加动画!,安卓系统是谷歌在2008年设计和制造的。操作系统主要写在爪哇,C和C 的核心组件。它是在linux内核之上构建的,具有安全性优势。
android-sdk-sources-android-28.rar
android_animations:Android动画-准备使用XML文件
在此处获得此库的良好概述: : 一体化要在您的项目中使用AdditiveAnimator ,请在build.gradle添加以下几行: dependencies { compile 'at.wirecube:additive_animations:1.9.0'}...repositories { jcenter()}快速...
01_FirstApp 02_MVC 03_ActivityLifecycle 05_SecondActivity 06_AndroidVersions 07_UIFragments 08_LayoutsAndWidgets 09_RecyclerView 10_FragmentArguments 11_ViewPager ...33_MaterialDesignTopics
Animations Beautiful animations from AOSP 依賴 Add it in your root build.gradle at the end of repositories: allprojects { repositories { ... maven { url 'https://jitpack.io' } } } 查詢最新...
For making animations more real, I created another project named Android Easing Functions which is an implementations of easing functions on Android. So, we need to dependent that project. Step 1 ...
关于这个项目 PERSONAL Android 开发学习过程中,有两处重要的代码资料来源,一是 Android Training 及其 ...Android Training - Adding Animations,演示如何向应用中添加一些常见的动画,分为5个部分,包括详细的
详细解释了Android的animation四种类型:alpha、scale、translate、rotate,及其在代码中的获取与使用
Android 3.0 Animations Beginner’s Guide Android 3.0 中动画的操作
[android.开发书籍].Android.3.0.Animations.pdf
nineoldandroids 界面库 实习
RxAnimations is a library with the main goal to make android animations more solid and cohesive. Download compile 'oxim.digital:rx2anim:0.9.1' compile 'io.reactivex.rxjava2:rxandroid:2.0.1' ...
Packt.Android.3.0.Animations.Beginner's.Guide
本来想不要分的,但是最近的确有点缺分,我把android官网demo之animations.zip的拿出来看了一遍,然后整了一个eclipse可用的
它是一款实现了各种Material风格动画效果的开源项目,包括Activity之间的跳转动画,View的动画等。
This is a Calendar app with various animations
主要介绍了Android开发之Animations动画用法,结合实例形式详细分析了Animations动画的类型、组成、模式及对应的使用技巧,需要的朋友可以参考下
Python script to create android boot animations gifs
android-view-animations-java,Awesome Library可使用视图动画系统执行倾斜动画,如关注、反弹、淡入、翻转、旋转、滑动和缩放视图。.zip