TranslateAnimation动画

众所周知,TranslateAnimation是android中重要的一个动画函数,很多时候我们
都需要使用它来实现更好的UI效果,今天就简单研究下这个TranslateAnimation。
TranslateAnimation这个位移动画主要有三个构造函数,对应着三种不同的参数
形式,接下来使用源码简单分析,个人见解而已。

(1)第一种构造函数TranslateAnimation(Context context, AttributeSet attrs)
/*** Constructor used when a TranslateAnimation is loaded from a resource.* * @param context Application context to use* @param attrs Attribute set from which to read values*/public TranslateAnimation(Context context, AttributeSet attrs) {super(context, attrs);TypedArray a = context.obtainStyledAttributes(attrs,com.android.internal.R.styleable.TranslateAnimation);Description d = Description.parseValue(a.peekValue(com.android.internal.R.styleable.TranslateAnimation_fromXDelta));mFromXType = d.type;mFromXValue = d.value;d = Description.parseValue(a.peekValue(com.android.internal.R.styleable.TranslateAnimation_toXDelta));mToXType = d.type;mToXValue = d.value;d = Description.parseValue(a.peekValue(com.android.internal.R.styleable.TranslateAnimation_fromYDelta));mFromYType = d.type;mFromYValue = d.value;d = Description.parseValue(a.peekValue(com.android.internal.R.styleable.TranslateAnimation_toYDelta));mToYType = d.type;mToYValue = d.value;a.recycle();}

通过源码我们可以看出,这个构造函数,主要是当你从一个资源文件中获取一个动画资源时
进行调用,构造函数会自动帮你解析其中相应的参数,然后赋值给mFromXType,mFromXValue
...等8个参数。其实它就相当于接下来将要介绍的第三个构造函数,只不过这个构造函数
传入的是context和资源文件对你的动画属性的封装参数attrs。而第二个构造也是第三个
构造函数的一种特殊情况。

(2)第二种构造函数TranslateAnimation(float fromXDelta, float toXDelta, float fromYDelta, float toYDelta)
/*** Constructor to use when building a TranslateAnimation from code* * @param fromXDelta Change in X coordinate to apply at the start of the*        animation* @param toXDelta Change in X coordinate to apply at the end of the*        animation* @param fromYDelta Change in Y coordinate to apply at the start of the*        animation* @param toYDelta Change in Y coordinate to apply at the end of the*        animation*/public TranslateAnimation(float fromXDelta, float toXDelta, float fromYDelta, float toYDelta) {mFromXValue = fromXDelta;mToXValue = toXDelta;mFromYValue = fromYDelta;mToYValue = toYDelta;mFromXType = ABSOLUTE;mToXType = ABSOLUTE;mFromYType = ABSOLUTE;mToYType = ABSOLUTE;}

这个构造函数的参数
  float fromXDelta:这个参数表示动画开始的点离当前View X坐标上的差值;
  float toXDelta, 这个参数表示动画结束的点离当前View X坐标上的差值;
  float fromYDelta, 这个参数表示动画开始的点离当前View Y坐标上的差值;
  float toYDelta)这个参数表示动画开始的点离当前View Y坐标上的差值;
也就是说你的TranslateAnimation动画执行的整个过程,需要你指定它的起始位置,而这个起始位置的确定要
依靠你原来的View的位置为参照,如果你View的位置为(x,y),则动画开始的位置坐标为(x+fromXDelta, y+fromYDelta)
它的结束位置为(x+toXDelta,y+toYDelta)。再看源码你会发现构造函数又设置了四个参数为默认的ABSOLUTE,这个参数
表示绝对像素,在接下里的最后一个构造函数中可以由你来自己选定,而这个函数也其实就是下一个构造函数的一种
X方向或者Y方向上的Type选定为Animation.ABSOLUTE的特殊情况。

(3)第三种构造函数TranslateAnimation(int fromXType, float fromXValue, int toXType, float toXValue,int fromYType, float fromYValue, int toYType, float toYValue) 
 /*** Constructor to use when building a TranslateAnimation from code* * @param fromXType Specifies how fromXValue should be interpreted. One of*        Animation.ABSOLUTE, Animation.RELATIVE_TO_SELF, or*        Animation.RELATIVE_TO_PARENT.* @param fromXValue Change in X coordinate to apply at the start of the*        animation. This value can either be an absolute number if fromXType*        is ABSOLUTE, or a percentage (where 1.0 is 100%) otherwise.* @param toXType Specifies how toXValue should be interpreted. One of*        Animation.ABSOLUTE, Animation.RELATIVE_TO_SELF, or*        Animation.RELATIVE_TO_PARENT.* @param toXValue Change in X coordinate to apply at the end of the*        animation. This value can either be an absolute number if toXType*        is ABSOLUTE, or a percentage (where 1.0 is 100%) otherwise.* @param fromYType Specifies how fromYValue should be interpreted. One of*        Animation.ABSOLUTE, Animation.RELATIVE_TO_SELF, or*        Animation.RELATIVE_TO_PARENT.* @param fromYValue Change in Y coordinate to apply at the start of the*        animation. This value can either be an absolute number if fromYType*        is ABSOLUTE, or a percentage (where 1.0 is 100%) otherwise.* @param toYType Specifies how toYValue should be interpreted. One of*        Animation.ABSOLUTE, Animation.RELATIVE_TO_SELF, or*        Animation.RELATIVE_TO_PARENT.* @param toYValue Change in Y coordinate to apply at the end of the*        animation. This value can either be an absolute number if toYType*        is ABSOLUTE, or a percentage (where 1.0 is 100%) otherwise.*/public TranslateAnimation(int fromXType, float fromXValue, int toXType, float toXValue,int fromYType, float fromYValue, int toYType, float toYValue) {mFromXValue = fromXValue;mToXValue = toXValue;mFromYValue = fromYValue;mToYValue = toYValue;mFromXType = fromXType;mToXType = toXType;mFromYType = fromYType;mToYType = toYType;}

在这个构造函数中共有8个参数
Animation.ABSOLUTE是绝对位移量,也就是上面的第二种构造函数的情况,当使用这个参数时,这两种构造函数并无差别
Animation.RELATIVE_TO_SELF
Animation.RELATIVE_TO_PARENT这两个参数是相对位移量,也就是说相对于这个View自己,或者是相对于这个控件的父控件
的。当使用这两个Type时,相应的fromXValue,toXValue,fromYValue,toYValue的值是double型的数据,可正也可负。
例如当Type为RELATIVE_TO_SELF,且fromXValue为+1.0时,也就代表着你的动画的初始位置x坐标在原来视图X坐标位置的正方向偏移一个自身宽度。而当值为0时
就意味着你这个View的x轴位置相对于你自身原来X轴位置不变。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/453552.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

maven项目使用jacoco插件检测代码覆盖率详细配置

使用maven构建项目&#xff08;java项目或者web项目都可以&#xff09; jacoco插件的配置参考官方网址&#xff1a;http://www.eclemma.org/jacoco/trunk/doc/maven.html &#xff08;1&#xff09;配置jacoco的依赖jar包 <dependency><groupId>org.jacoco</gro…

JAVA如何取得空list成员类型_String 类型的List作为一个成员变量保存,保存成功后取对象时报空指针...

异常&#xff1a;Caused by: java.lang.NullPointerException at org.litepal.crud.DataHandler.setToModelByReflection(DataHandler.java:1341) at org.litepal.crud.DataHandler.setGenericValueToModel(DataHandler.java:787) at org.litepal.crud.DataHandler.query(DataH…

C语言:几种字符输入函数的区别

几种字符输入函数的区别&#xff1a; 1、getche()函数:用于从键盘读入一个字符并显示&#xff0c;然后直接执行下一条语 句。2、getch()函数:用于从键盘中读入一个字符&#xff0c;但不显示在屏幕上&#xff0c;然后执行下一条语句。3、getchar()函数&#xff1a;用于从键盘读…

VCG Mesh刚性旋转(变换矩阵)

文章目录 一、简介二、实现代码三、实现效果参考资料一、简介 旋转矩阵如果从线性空间的角度来看,它类似于一个投影过程。假设坐标 P ( x 1 , y 1 , z 1 ) P(x_1,y_1,z_1)

薪水增长多少,新机会才值得考虑?

薪水增长多少,新机会才值得考虑? 阴历年马上就要来到&#xff0c;猪年正在向我们招手。相信有些朋友年后考虑新的要作机会&#xff0c;年终奖和第13个薪水已到手&#xff0c;是考虑一下离开这个让自己不“爽”公司的时候了&#xff0c;哈哈&#xff01; 但是&#xff0c;薪水…

ScaleAnimation动画

ScaleAnimation动画是用来进行缩放的动画&#xff0c;我在使用时刚开始有些不解的问题后来经过学习&#xff0c;有了一个更深的了解。先来看看源码&#xff0c;其实ScaleAnimation有四个构造函数&#xff0c;这里我只列出了其中的一个&#xff0c;因为另外的三个其实都只是这个…

Swift快速入门(一)第一个Swift程序

1. 本系列说明 本系列只是一个Swift快速入门的教程&#xff0c;并没有详尽的介绍Swift&#xff0c;Swift也并不是一个简单的编程语言&#xff0c;所以要想详尽的系统的学习Swift&#xff0c;本系列并不适合你&#xff0c;此系列只是让开发者可以快速的用Swift来进行开发。另外学…

java 判断数字变化增减_java String 强化操作 判断数字 字符串转阿拉伯数字,相似度等等...

importjava.io.BufferedReader;importjava.io.StringReader;importjava.util.ArrayList;importjava.util.List;importjava.util.regex.Matcher;importjava.util.regex.Pattern;/***author*/public classStrings {/*** 全角转半角**paramsbc 全角字符*returnString*/public stat…

[CareerCup] 4.7 Lowest Common Ancestor of a Binary Search Tree 二叉树的最小共同父节点

4.7 Design an algorithm and write code to find the first common ancestor of two nodes in a binary tree. Avoid storing additional nodes in a data structure. NOTE: This is not necessarily a binary search tree. LeetCode上的原题&#xff0c;请参见我之前的博客Lo…

让猎头雨天送伞--大话猎头

让猎头雨天送伞--大话猎头(1) Arthur毕业之后&#xff0c;在一同家公司的研发部工作了7年&#xff0c;从初级开发工程师一直做到项目经理&#xff0c;过手十几个大项目&#xff0c;现在带领8人的研发团队。猎头最近频频与他沟通&#xff0c;希望他考虑几个外企研发主管的机会…

android布局的一些知识

(一)android:layout_alignParentBottom 控制该组件是否与布局容器底端对齐android:layout_alignParentLeft 控制该组件是否与布局容器左边对齐android:layout_alignParentRight 控制该组件是否与布局容器右边对齐android:layout_alignParentTop 控制该组件是否与布局容器顶端对…

IE8兼容问题总结---trim()方法

1.IE8不支持,jquery的trim()去空格的方法 错误表现 : 会报错,对象不支持此属性或方法; 解决办法 : 使用正则匹配空格 例如 : /^\s|\s$/greplace(/^\s|\s$/g,"");转载于:https://www.cnblogs.com/lizhiwei8/p/8392589.html

java的流套接_java-使用流关闭套接字

我的以下问题非常简单.这是我的代码&#xff1a;public class Protocol implements Runnable {private SSLSocket socket null;private InputStream is null;private OutputStream os null;...public Protocol(Socket s) {socket (SSLSocket)s;is socket.getInputStream()…

简历撰写

没什么可写的项目&#xff0c;或者自己说不太清&#xff0c;效果也不明显的项目&#xff0c;就不要写简历上了转载于:https://www.cnblogs.com/brainstorm/p/7942669.html

如何真正做好项目管理?

项目要能顺利执行其实并不简单&#xff0c;如果又渉及多个单位合作&#xff0c;困难程度又大增。 从项目经理的工作日志片段&#xff0c;可以看出每个项目经理应该都有自已悲惨的故事&#xff0c;程度恐怕只有过之而无不及。项目经理到底应该有那些看家本领呢&#xff1f; …

日历视图的XML属性

日历视图的XML属性 : -- 设置样式 : android:dateTextAppearance, 设置日期文字显示样式; -- 设置首日 : android:firstDayOfWeek, 设置星期几是每周的第一天, 默认是周一; -- 选中颜色 : android:focusedMonthDateColor, 设置选中日期所在月份日期颜色; -- 最大日期 : android…

作业30-首页列表显示全部问答,完成问答详情页布局

首页列表显示全部问答&#xff1a;将数据库查询结果传递到前端页面 Question.query.all()前端页面循环显示整个列表。问答排序app.route(/) def index():context{questions:Question.order_by(creat_time).query.all()}return render_template("index.html",**contex…

java重置radiobutton的选项_求助:这道题显示radiobutton男女的功能和重置功能怎么做...

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼package org.demo.app.gui; import java.awt.BorderLayout;import java.awt.Color;import java.awt.Container;import java.awt.GridLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax…

PopupWindow和AlertDialog区别

1 第一个重要的区别是AlertDialog不能指定显示位置&#xff0c;只能默认显示在 屏幕最中间&#xff08;当然也可以通过设置WindowManager参数来改变位置&#xff09;。 而PopupWindow是可以指定显示位置的&#xff0c;随便哪个位置都可以&#xff0c;更加灵活。 2 AlertDia…

Scala学习之爬豆瓣电影

简单使用Scala和Jsoup对豆瓣电影进行爬虫&#xff0c;技术比較简单易学。写文章不易&#xff0c;欢迎大家採我的文章&#xff0c;以及给出实用的评论&#xff0c;当然大家也能够关注一下我的github&#xff1b;多谢。 1、爬虫前期准备 找好须要抓取的链接&#xff1a;https://m…