久久婷婷香蕉热狠狠综合,精品无码国产自产拍在线观看蜜,寡妇房东在做爰3,中文字幕日本人妻久久久免费,国产成人精品三上悠亚久久

當前位置:首頁 > 嵌入式培訓 > 嵌入式學習 > 講師博文 > 屬性動畫

屬性動畫 時間:2018-09-27      來源:未(wei)知

Android提供了(le)幾(ji)種動(dong)畫(hua)(hua)類(lei)型:View Animation(補間動(dong)畫(hua)(hua)) 、Drawable Animation (幀(zhen)動(dong)畫(hua)(hua))、Property Animation (屬性(xing)動(dong)畫(hua)(hua))。View Animation相當簡單,不(bu)過只能支(zhi)持簡單的(de)(de)縮(suo)放、平移、旋轉(zhuan)(zhuan)、透明度基本的(de)(de)動(dong)畫(hua)(hua),且有一(yi)定的(de)(de)局限性(xing)。比如:你(ni)(ni)希(xi)望View有一(yi)個顏色的(de)(de)切換(huan)動(dong)畫(hua)(hua);你(ni)(ni) 希(xi)望可以使(shi)用3D旋轉(zhuan)(zhuan)動(dong)畫(hua)(hua);你(ni)(ni)希(xi)望當動(dong)畫(hua)(hua)停止(zhi)時(shi),View的(de)(de)位置就是當前的(de)(de)位置;這些View Animation都(dou)無法做(zuo)到。這就是Property Animation產生的(de)(de) 原因。

新引入的(de)(de)(de)屬(shu)性動畫機制(zhi)已經不(bu)再是(shi)針對(dui)于View來設計的(de)(de)(de)了,也(ye)(ye)不(bu)限(xian)定于只能實(shi)現移動、縮(suo)放、旋轉和淡入淡出(chu)這幾種動畫操作,同時(shi)也(ye)(ye)不(bu)再只是(shi)一 種視覺上的(de)(de)(de)動畫效果了。它實(shi)際上是(shi)一種不(bu)斷地對(dui)值進行操作的(de)(de)(de)機制(zhi),并將值賦值到指定對(dui)象的(de)(de)(de)指定屬(shu)性上,可以是(shi)任(ren)意對(dui)象的(de)(de)(de)任(ren)意屬(shu)性。

一、相(xiang)關API

ObjectAnimator 動(dong)畫的執行(xing)類

ValueAnimator 動(dong)畫(hua)的執(zhi)行類

AnimatorSet 用于控制一組(zu)動畫的執行

setDuration() 設置動畫時間

start() 開始動畫

cancel() 停止(zhi)動畫在(zai)當前位(wei)置

end() 動畫直接到終狀態

setRepeatMode 設置(zhi)動畫(hua)重復方式

setRepeatCount設(she)置動畫重復次數

二、ObjectAnimator使用

ObjectAnimator是屬性動畫框架中重要的(de)實現(xian)類,創建一(yi)個ObjectAnimator只需要通過它的(de)靜態方法直接返回一(yi)個ObjectAnimator對象。靜態方 法如(ru)下:

ofFloat(Object target, String propertyName, float... values);

ofInt(Object target, String propertyName, int... values);

ofObject(Object target, String propertyName, TypeEvaluator evaluator, Object... values);

這里先關注ofFloat、ofint,方法中有三個(ge)參數(shu):

Target:指(zhi)定執行動畫的(de)view

propertyName:指定(ding)動畫的(de)屬(shu)性(xing)

values:可變數組(zu)參數,指定(ding)屬(shu)性(xing)對應的屬(shu)性(xing)值

如(ru)下所示,給(gei)imageview設置漸變(bian)的動畫。

ObjectAnimator animator = ObjectAnimator.ofFloat(imageview, "alpha";, 1.0f, 0.0f);

// 設置(zhi)時(shi)間(jian)

animator. setDuration(1000);

// 開始動畫

animator.start();

 

下(xia)面列舉出一些可以直接使用的屬性:

translationX、translationY:這兩個屬(shu)性作為一種增(zeng)量來(lai)控制著View對象從(cong)它布局容器的左上角坐標開(kai)始的位置。

rotation、rotationX、rotationY:這(zhe)三個屬性(xing)控制著View對象(xiang)圍(wei)繞它的支點進行2D和3D的旋轉。

 scaleX和scaleY:這兩個屬性控制著View對(dui)象圍繞(rao)它的(de)支點進行(xing)2D縮放(fang)。

alpha:它表示View對象(xiang)的alpha透明度。

二、ValueAnimator使用

ValueAnimator是整(zheng)個(ge)屬性(xing)動畫中核心的(de)一個(ge)類(lei),前(qian)面介紹的(de)ObjectAnimator也是繼承自ValueAnimator。

ValueAnimator本身不提供任(ren)何動畫效果,它(ta)更像一個(ge)數值(zhi)發生(sheng)器,用(yong)來產生(sheng)具有一定規律的(de)(de)數字,從而(er)讓調(diao)用(yong)者來控制動畫的(de)(de)實(shi)現過程。通常情 況下,在ValueAnimator的(de)(de)AnimatorUpdateListener中監聽數值(zhi)的(de)(de)變化,從而(er)完成(cheng)動畫的(de)(de)切(qie)換(huan)。

如下所示,利(li)用ValueAnimator給imageview設置漸變的動畫。

ValueAnimator animator = ValueAnimator.ofFloat(1.0f, 0.0f);

animator.setDuration(1000);

animator.start();

// 反復循環,REATART從(cong)頭開(kai)始循環

animator.setRepeatMode(ValueAnimator.REVERSE);

animator.setRepeatCount(ValueAnimator.INFINITE);// 無限循環

 animator.addUpdateListener(new AnimatorUpdateListener() {

@Override

public void onAnimationUpdate(ValueAnimator animation) {

 imageView.setAlpha((Float)animation.getAnimatedValue());

}

});

三、AnimatorSet使(shi)用(yong)

AnimatorSet這個(ge)(ge)(ge)類來(lai)幫(bang)我們實現組合屬性動(dong)畫的(de)效果(guo)。AnimatorSet這個(ge)(ge)(ge)類提供(gong)了一(yi)個(ge)(ge)(ge)play()方法,如果(guo)我們向這個(ge)(ge)(ge)方法中傳入(ru)一(yi)個(ge)(ge)(ge)Animator對(dui)象 (ObjectAnimator或者(zhe)ValueAnimator)將會返回一(yi)個(ge)(ge)(ge)AnimatorSet.Builder的(de)實例,AnimatorSet.Builder中包含(han)了以下四(si)個(ge)(ge)(ge)方法:

after(Animator anim) : 將現有動畫插入到(dao)傳入的動畫之后(hou)執(zhi)行。

after(long delay):將現有的動畫延遲指定的毫秒后(hou)執行。

before(Animator anim):將現有(you)的(de)動(dong)畫插(cha)入到傳入的(de)動(dong)畫之前(qian)執行。

with(Animator anim):將(jiang)現有的動畫(hua)和傳入的動畫(hua)同時執行。

// 移(yi)動動畫

ObjectAnimator transAnimator = ObjectAnimator.ofFloat(mTextView, "translationX", -500f, 300f);

// 旋轉(zhuan)動(dong)畫

ObjectAnimator rotationAnimator = ObjectAnimator.ofFloat(mTextView, "rotation", 0f, 360f);

// 淡(dan)入淡(dan)出

ObjectAnimator alphaAnimator = ObjectAnimator.ofFloat(mTextView, "alpha", 1f, 0f, 1f);

AnimatorSet animatorSet = new AnimatorSet();

animatorSet.play(rotationAnimator).with(alphaAnimator).after(transAnimator);

animatorSet.setDuration(5000);

animatorSet.start();

四(si)、Animator監聽(ting)器(qi)

對(dui)于動(dong)畫(hua)(hua),一(yi)般都是一(yi)些輔助效(xiao)果,比喻說一(yi)個view動(dong)畫(hua)(hua)結束后里一(yi)個view開始動(dong)畫(hua)(hua),這就需(xu)要對(dui)動(dong)畫(hua)(hua)過程(cheng)進行(xing)監(jian)聽。通(tong)過實現AnimatorListener 接口即(ji)可(ke)對(dui)動(dong)畫(hua)(hua)的Start、End、Repeat、Cancel四(si)個狀態(tai)監(jian)聽。

animator.addListener(new Animator.AnimatorListener() {

@Override

public void onAnimationStart(Animator animation) {

Log.e("tag", "onAnimationStart");

}

@Override

public void onAnimationEnd(Animator animation) {

Log.e("tag", "onAnimationEnd");

}

@Override

public void onAnimationCancel(Animator animation) {

Log.e("tag", "onAnimationCancel");

}

@Override

public void onAnimationRepeat(Animator animation) {

Log.e("tag", "onAnimationRepeat");

}

})

上一篇:簡析靜態庫與動態庫

下一篇:數據拷貝的方法解析

熱點文(wen)章推薦
華清學員(yuan)就(jiu)業榜(bang)單
高薪學(xue)員經驗分享
熱(re)點(dian)新聞推薦
前(qian)臺專線(xian):010-82525158 企業培訓(xun)洽(qia)談專(zhuan)線(xian):010-82525379 院校合作洽談專線:010-82525379 Copyright © 2004-2022 北京華清遠見科技集團有限公司 版權所有 ,,京公海網安備11010802025203號

回到頂部