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.pswp.cn/news/453552.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/453552.shtml
英文地址,請注明出處:http://en.pswp.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…