animation- 动画效果实现(代码中)
1,首先我们看一下如下的代码
- import android.view.animation.LayoutAnimationController;
- import android.view.animation.Animation.AnimationListener;
- import android.view.animation.Transformation;
- import android.view.animation.Animation.AnimationListener;
- import android.view.animation.AlphaAnimation;
- import android.view.animation.TranslateAnimation;
- private Animation myHistoryAnimation;
- private LayoutAnimationController myLayoutControl;
- private AlphaAnimation myHistoryAlphaAnimation;
- private AlphaAnimation myHistoryAlphaAnimationConTime;
- private TranslateAnimation myHistoryTranslateAnimation;
- private AnimationSet myHistoryAnimationSet;
- myHistoryAlphaAnimation = new AlphaAnimation(1, 0);
- myHistoryAlphaAnimationConTime = new AlphaAnimation(1, 1);
- myHistoryAlphaAnimation.setDuration(1000);
- myHistoryAlphaAnimationConTime.setDuration(500);
- myHistoryAnimationSet = new AnimationSet(true);
- /* Vanzo:zhangshuli on: Fri, 20 Mar 2015 14:57:37 +0000
- * modify for v5 calculator
- myHistoryTranslateAnimation = (TranslateAnimation) AnimationUtils.loadAnimation(
- this, R.anim.history_clear_anim);
- */
- myHistoryTranslateAnimation = new TranslateAnimation(
- Animation.RELATIVE_TO_SELF,0f,
- Animation.RELATIVE_TO_SELF,0f,
- Animation.RELATIVE_TO_SELF,0f,
- Animation.RELATIVE_TO_SELF,10f);
- myHistoryTranslateAnimation.setDuration(1000);
- // End of Vanzo: zhangshuli
- myHistoryAnimationSet.setFillAfter(true);
- myHistoryAnimationSet.setAnimationListener(new AnimationListener() {
- @Override
- public void onAnimationStart(Animation arg0) {
- // TODO Auto-generated method stub
- history_clear_choose.setVisibility(View.GONE);
- }
- @Override
- public void onAnimationRepeat(Animation arg0) {
- // TODO Auto-generated method stub
- }
- @Override
- public void onAnimationEnd(Animation arg0) {
- // TODO Auto-generated method stub
- android.util.Log.e("zhangshuli", "set");
- /* Vanzo:zhangshuli on: Fri, 20 Mar 2015 16:17:24 +0000
- * modify for v5 calculator
- if (mDrawerLayout.isDrawerVisible(GravityCompat.END)) {
- mDrawerLayout.closeDrawer(GravityCompat.END);
- }
- */
- // End of Vanzo: zhangshuli
- }
- });
- myHistoryAlphaAnimation.setAnimationListener(new AnimationListener() {
- @Override
- public void onAnimationStart(Animation arg0) {
- // TODO Auto-generated method stub
- }
- @Override
- public void onAnimationRepeat(Animation arg0) {
- // TODO Auto-generated method stub
- }
- @Override
- public void onAnimationEnd(Animation arg0) {
- mHistory.clear();
- mLogic.onClear();
- android.util.Log.e("zhangshuli", "tran1");
- }
- });
- myHistoryAnimationSet.addAnimation(myHistoryTranslateAnimation);
- myHistoryAnimationSet.addAnimation(myHistoryAlphaAnimation);
- myHistoryAnimationSet.addAnimation(myHistoryAlphaAnimationConTime);
- myLayoutControl = new LayoutAnimationController(myHistoryAnimationSet);
- myLayoutControl.setDelay(0.1f);
- // myLayoutControl.setOrder(LayoutAnimationController.ORDER_NORMAL);
- myLayoutControl.setOrder(LayoutAnimationController.ORDER_REVERSE);
- mHistoryDisplayList.setLayoutAnimation(myLayoutControl);
2.从以上的代码中我们可以发现。代码中定义动画的话,有个好处,就是比较灵活,可以根据我们的需要动态的更改动画的时间等属性。当然,你也会看到它代码的重用性非常的糟糕。
1)创建动画:其实就是new一个相应的动画就行了
2)然后就是设置动画的属性值,时间等
- import android.view.animation.AlphaAnimation;
- AlphaAnimation alphaAnimation=new AlphaAnimation( 1f,0.5f);
- //动画时间
- alphaAnimation.setDuration(1000);
- //动画结束以后是否应用,false的话,会返回初始位置
- alphaAnimation.setFillAfter(true);
- //设置动画动作样式
- alphaAnimation.setInterpolator(this,android.R.anim.accelerate_decelerate_interpolator);
其他的也类似
- import android.view.animation.Animation;
- import android.view.animation.TranslateAnimation;
- TranslateAnimation translateAnimation = new TranslateAnimation(
- //第一个参数:相对于父类还是自身比例 第二个其实x坐标
- Animation.RELATIVE_TO_SELF, 0f,
- //起始y坐标
- Animation.RELATIVE_TO_SELF,0f,
- //结束x坐标
- Animation.RELATIVE_TO_SELF,0f,
- //结束y坐标
- Animation.RELATIVE_TO_SELF,10f);
3)如果你仅仅就需要一个简单的动画,那么你只需要在一个控件上start这个动画就行了,如下
- view.startAnimation(myAnimation_Alpha);
4)如果你希望把几个动画进行复合,这时候你需要借助
- myHistoryAnimationSet = new AnimationSet(true);
- myHistoryAnimationSet.addAnimation(myHistoryTranslateAnimation);
AnimationSet 其实就相当于一个动画容器,可以把不同的动画效果合为一个复合动画进行
animation- 动画效果实现(代码中)的更多相关文章
- Android中xml设置Animation动画效果详解
在 Android 中, Animation 动画效果的实现可以通过两种方式进行实现,一种是 tweened animation 渐变动画,另一种是 frame by frame animation ...
- android中设置Animation 动画效果
在 Android 中, Animation 动画效果的实现可以通过两种方式进行实现,一种是 tweened animation 渐变动画,另一种是 frame by frame animation ...
- 模仿百度首页“元宵节汤圆”动图,并实现360°不停旋转(CSS3的animation动画效果)
模仿百度首页“元宵节汤圆”动图,并实现360°不停旋转(CSS3的animation动画效果) 效果图: 切图地址: https://ss1.bdstatic.com/5eN1bjq8AAUYm2zg ...
- 右上角鼠标滑过展开收缩动画效果js代码的演示页面
http://files.cnblogs.com/files/tanlingdangan/top_right.rar.gz 右上角鼠标滑过展开收缩动画效果js代码的演示页面http://www.51x ...
- android Animation 动画效果介绍
Android的animation由四种类型组成 XML中 alpha 渐变透明度动画效果 scale 渐变尺寸伸缩动画效果 translate 画面转换位置移动动画效果 rotate 画面转移旋转动 ...
- ios animation 动画效果实现
1.过渡动画 CATransition CATransition *animation = [CATransition animation]; [animation setDuration:1.0]; ...
- Android Animation动画效果简介
AlphaAnimation 淡入淡出动画 <alpha>A fade-in or fade-out animation. Represents an AlphaAnimation. a ...
- Animation(动画效果)
Ctrl+6打开Animation窗口.选择物体,点击录制,保存录制文件后即为给该物体添加了动画效果. Animation可以修改某时间点的物体位置.大小.材质球上的所有属性.碰撞器等等. 可以通过修 ...
- H5中需要掌握的 ANIMATION 动画效果
CSS3的动画在PC网页上或者APP上用得越来越多,比如H5页面的应用,目前在营销传播上的意义比较大,还有企业官网或者APP主要介绍也用得比较多,当然还有很多地方都用到.所以学习css的动画也迫在眉睫 ...
- UITableview reloadData Animation 动画效果
http://blog.kingiol.com/blog/2013/10/22/uitableview-reloaddata-with-animation/ 运用到UITableview进行重新加载数 ...
随机推荐
- iOS菜鸟成长笔记(1)——第一个iOS应用
前言:阳光小强最近抽时间学习iOS开发,在学习过程中发现了很多有趣的东西也遇到了很多问题,为了在学习过程中能和大家交流,记录下学习的心得和学习成果,所以就有了这一个系列文章,希望这一系列文章能形成一个 ...
- vue父子间通信案列三($emit和prop用法)
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- HDU 4513 吉哥系列故事――完美队形II
http://acm.hdu.edu.cn/showproblem.php?pid=4513 吉哥系列故事——完美队形II Time Limit: 3000/1000 MS (Java/Others) ...
- Aspose.Cells相应操作及下载
Aspose.Cells相应操作 1,上传 1.1 Workbook Workbook workBook = new Workbook(); 属性: 名称 值类型 说明 Colors Color[] ...
- Android学习总结(1)——好的 Android 开发习惯
Android编码规范 java代码中不出现中文,最多注释中可以出现中文: 局部变量命名.静态成员变量命名:只能包含字母,单词首字母出第一个都为大写,其他字母都为小写: 常量命名:只能包含字母和 ,字 ...
- Springboot集成mybatis通用Mapper与分页插件PageHelper
插件介绍 通用 Mapper 是一个可以实现任意 MyBatis 通用方法的框架,项目提供了常规的增删改查操作以及 Example 相关的单表操作.通用 Mapper 是为了解决 MyBatis 使用 ...
- 《linux 内核全然剖析》编译linux 0.12 内核 Ubuntu 64bits 环境
我×.. . 最终好了,大概3 4个小时吧...各种毛刺问题.终究还是闯过来了.. .. ubuntu2@ubuntu:~/Downloads/linux-0.00-050613/linux-0.00 ...
- jquery autocomplete文本自己主动补全
文本自己主动补全功能确实非常有用. 先看下简单的效果:(样式不咋会写) 以下介绍几种: 1:jqery-actocomplete.js 这个网上有个写好的实例,上面挺具体的,能够下来执行下就清楚了就不 ...
- 【Oracle】使用bbed恢复delete的数据
表中的数据被delete之后并不会真正删除数据,而是打了一个删除标记,仅仅要还没有被覆盖就能够恢复回来. 实验步骤例如以下: SYS@ORCL>create table bbed_test(x ...
- js -- 分页功能
html 代码 <html> <head> <meta charset='utf-8'> <script type="text/javascript ...