Android开发属性动画
普通动画效果和属性动画效果区别:
普通动画效果的动画播放后只是产生了视觉欺骗,并没有移动真实的控件。
属性动画直接真实的移动控件
AnimationSet动画:
TextView t1 = (TextView)findViewById(R.id.textView6);
TextView t2 = (TextView)findViewById(R.id.textView7); //设置移动
AnimationSet animationSet = new AnimationSet(true);
TranslateAnimation translateAnimation = new TranslateAnimation(
Animation.RELATIVE_TO_SELF,0f,
Animation.RELATIVE_TO_SELF,-2f,
Animation.RELATIVE_TO_SELF,0f,
Animation.RELATIVE_TO_SELF,0f
);
//设置透明度
AlphaAnimation alphaAnimation = new AlphaAnimation(1,0);
//添加进去
animationSet.addAnimation(translateAnimation);
animationSet.addAnimation(alphaAnimation);
animationSet.setDuration(500);
t1.startAnimation(animationSet);
t1.setVisibility(View.GONE);
属性动画:
RelativeLayout relativeLayout = (RelativeLayout) findViewById(R.id.foot);
float curTranslationY = relativeLayout.getTranslationY();
ObjectAnimator animator = ObjectAnimator.ofFloat(relativeLayout, "translationY", curTranslationY, -300f);
animator.setDuration(200);
animator.start();
总的来说属性动画执行的动画效果后控件的位置也会发生改变,解决了很多麻烦。
ObjectAnimator animator = ObjectAnimator.ofFloat(relativeLayout, "translationY", curTranslationY, -300f);
这里的4个参数分别代表的是
1.要进行操作的控件
2.执行的动画效果,我这里的是沿着Y移动 translationX 是沿着X轴移动 rotationX 就是旋转了
至于后面的几个参数就是移动的位置了如果添加第5个参数那么 3 - 5 的参数代表的就是 (从第3个参数移动到第4个参数,然后返回到第5个参数)
ObjectAnimator animator = ObjectAnimator.ofFloat(relativeLayout, "translationY", curTranslationY, -300f,curTranslationY);
上面的代码代表的就是从curTranslationY开始移动 移动到 -300f 然后 返回到 curTranslationY 的位置。
animator.setDuration(200);
animator.start();
上面第一行代码代表整个动画执行的时间,这里是200毫秒。
最后一行代码开始执行动画效果。
Android开发属性动画的更多相关文章
- Android开发——View动画、帧动画和属性动画详解
0. 前言 Android动画是面试的时候经常被问到的话题.我们都知道Android动画分为三类:View动画.帧动画和属性动画. 先对这三种动画做一个概述: View动画是一种渐进式动画,通过图 ...
- android使用属性动画代替补间动画
本文参考Android属性动画完全解析(上),初识属性动画的基本用法 android3.0之前一共有两种动画,分别是frame动画和tween动画,关于这两种动画如果不了解可以查看我之前的文章andr ...
- Android开发学习——动画
帧动画> 一张张图片不断的切换,形成动画效果* 在drawable目录下定义xml文件,子节点为animation-list,在这里定义要显示的图片和每张图片的显示时长 ...
- 【Android】属性动画
转载请注明出处:http://blog.csdn.net/h28496/44338669 属性动画的原理 通过不断的设置一个View的属性让其出现动画效果.比如,不断地设置一个Button的x值.这个 ...
- Android之属性动画(二)
上一篇文章(链接:http://www.cnblogs.com/jerehedu/p/4458928.html ),我们对属性动画有了简单的认识,并实际动手使用ObjectAnimator.Anim ...
- Android之属性动画(一)
一.概述 Android平台中常用的动画主要有两类,一类是View动画,一类是3.0后新增的属性动画.属性动画与View动画相比功能更加强大,主要体现在以下两个方面: 1. 属性动画不仅仅能应用到V ...
- android开发之动画的详解 整理资料 Android开发程序小冰整理
/** * 作者:David Zheng on 2015/11/7 15:38 * * 网站:http://www.93sec.cc * * 微博:http://weibo.com/mcxiaob ...
- IOS开发-属性动画和关键帧动画的使用
CAMediaTiming是一个协议(protocol),CAAnimation是所有动画类的父类,但是它不能直接使用,应该使用它的子类. 继承关系: CoreAnmiation 核心动画 简写CA ...
- Android使用属性动画ValueAnimator动态改变SurfaceView的背景颜色
以下是主要代码,难点和疑问点都写在注释中: /** * 开始背景动画(此处为属性动画) */ private void startBackgroundAnimator(){ /* *参数解释: *ta ...
随机推荐
- CentOS7中安装redis5.0
1. 环境介绍 CentOS7 (未安装Development Tools) 2. 下载Redis5.0-rc3 wget -O redis-5.0-rc3.tar.gz https://github ...
- centos6.5虚拟机安装后,没有iptables配置文件
openstack环境里安装centos6.5系统的虚拟机,安装好后,发现没有/etc/syscofig/iptables防火墙配置文件. 解决办法如下: [root@kvm-server005 ~] ...
- L2-027. 名人堂与代金券
链接:名人堂与代金券 在比赛中这题只得了2分,赛后发现原来strcmp函数并不是只返回-1,0,1三种,而是返回正数负数0 但是在我的电脑上一般就是返回前三种,只是用后面的三种更稳妥点 都怪我基础不扎 ...
- 【CV】ICCV2015_Unsupervised Learning of Spatiotemporally Coherent Metrics
Unsupervised Learning of Spatiotemporally Coherent Metrics Note here: it's a learning note on the to ...
- Linux内核及分析 第三周 Linux内核的启动过程
实验过程: 打开shell终端,执行以下命令: cd LinuxKernel/ qemu -kernel linux-3.18.6/arch/x86/boot/bzImage-initrd rootf ...
- PHP开发:Eclipse版环境配置
软件: 1.eclipse php版本下载地址:http://www.eclipse.org/downloads/packages/eclipse-php-developers/heliosr 2.A ...
- org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [applicationContext.xml]; nested exception is java.io.FileNotFoundException: c
//这个是 配置文件放错了地方 org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing ...
- Linux 忘记root密码
1 将系统重启,读秒的时候按下任意键就会出现如下图菜单界面 2 进入上图菜单界面之后,按e键就可以进入grub的编辑模式 3 选择第二行 kernel开头,再按 e 键进入该行的编辑界面中,然后在出现 ...
- Linux下DB2命令学习及整理
DB2相关数据库命令 1.数据库实例的启动首先要启动数据库的实例,即切换到db2inst1用户(注:db2inst1用户为当前数据库的实例),然后执行db2start启动数据库的实例 [root@lo ...
- ElasticSearch 6.x head插件安装
一.下载node.js yum install -y nodejs 二.安装npm npm install -g cnpm --registry=https://registry.npm.taobao ...