android動畫-Property Animation

來源:互聯網
上載者:User

標籤:property   animation   android   

 Property Animation 屬性動畫,這個是在Android 3.0中才引進的。
    Property Animation其改變的是對象屬性對應的值,應用於任何對象,而Tween Animation更改的是繪畫的效果,其屬性值是沒有變化的。

ObjectAnimator:更改對象的屬性值
  使用方法:
  ObjectAnimator translationRight = ObjectAnimator.ofFloat(m_tv, "X",width);
  translationRight.setDuration(1500);
  translationRight.start();
  這是一個平移的效果,ObjectAnimator.ofFloat(m_tv, "X",width);第一個參數是:對象 第二個參數:該對象的屬性,屬性有必須有對應的getX()和setX()方法,第三個參數:一個可變參數的值
  如果唯寫了一個值,那麼就預設從當前的值變為填寫的值,如果填寫了多個,就按照填寫的順序做相應的變化,
  setDuration():設定啟動並執行時間,start():開啟
  
AnimatorSet:將多個ObjectAnimator的效果一直執行或則按照先後順序執行
        ObjectAnimator translationRight = ObjectAnimator.ofFloat(m_tv, "X",width);
ObjectAnimator translationLeft = ObjectAnimator.ofFloat(m_tv, "X", 0f);
ObjectAnimator translationDown = ObjectAnimator.ofFloat(m_tv, "Y",height);
ObjectAnimator translationUp = ObjectAnimator.ofFloat(m_tv, "Y", 0);
AnimatorSet as = new AnimatorSet();
as.play(translationRight).before(translationLeft);
as.play(translationRight).with(translationDown);
as.play(translationLeft).with(translationUp);
paly() with()  before()  after() 設定執行的順序 start()開啟

下面代碼的介紹請參考:  http://www.open-open.com/lib/view/open1329994048671.html
ValueAnimator,TypeEvalutors,TimeInterplator,Keyframes



部分範例程式碼:

<span style="font-family:SimSun;font-size:18px;"><?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="vertical" >    <ImageView        android:id="@+id/image"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:background="@drawable/girl" />    <EditText        android:id="@+id/edit_text"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:layout_margin="5dp" /></LinearLayout></span>


實現:
<span style="font-family:SimSun;font-size:18px;">private void initImageAnimationSet() {ImageView image = (ImageView) findViewById(R.id.image);ObjectAnimator obOutX = ObjectAnimator.ofFloat(image, "X", 200);ObjectAnimator obOutY = ObjectAnimator.ofFloat(image, "Y", 200);ObjectAnimator obInX = ObjectAnimator.ofFloat(image, "X", 0);ObjectAnimator obInY = ObjectAnimator.ofFloat(image, "Y", 0);final AnimatorSet set = new AnimatorSet();set.play(obOutX).with(obOutY);set.play(obInX).with(obInY);set.play(obOutX).before(obInX);image.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {set.start();}});}/** * ObjectAnimator使用 */private void initEditObjectAnimator() {EditText edt = (EditText) findViewById(R.id.edit_text);final ObjectAnimator translationRight = ObjectAnimator.ofFloat(edt,"X", 0, 50, -10, 40, -5, 30, -3, 20, -1, 10, 0);translationRight.setDuration(1500);edt.addTextChangedListener(new TextWatcher() {@Overridepublic void onTextChanged(CharSequence s, int start, int before,int count) {}@Overridepublic void beforeTextChanged(CharSequence s, int start, int count,int after) {}@Overridepublic void afterTextChanged(Editable s) {if (TextUtils.isEmpty(s.toString())) {translationRight.start();}}});}</span>


案例代碼下載:

:



  
  

 



   

android動畫-Property Animation

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.