淺談Android中視圖動畫的屬性與使用_Android

來源:互聯網
上載者:User

簡介

Android動畫主要包括視圖動畫和屬性動畫,視圖動畫包括Tween動畫和Frame動畫,Tween動畫又包括漸層動畫、平移動畫、縮放動畫、旋轉動畫。

Tween動畫的基本屬性

      目標 View;

      時常 duration;

      開始狀態 fromXXX;

      結束動畫 toXXX;

      開始時間 startOffset;

      重複次數 repeatCount;

      時間軸 interpolator(插值器)。

程式碼範例

xml實現

<?xml version="1.0" encoding="utf-8"?> <translate xmlns:android="http://schemas.android.com/apk/res/android" android:fromXDelta="0" android:fromYDelta="0" android:toXDelta="100%" android:toYDelta="0" android:fillAfter="true" android:duration="3000"></translate>

在代碼中調用

Animation translate = AnimationUtils.loadAnimation(context,R.anim.translate);imageView.startAnimation(translate);

補充:

1.對於縮放和旋轉動畫,有一個pivotX或者pivotY,表示的是縮放或旋轉的中心點。

對應的屬性值有三種寫法。

     · 數值 50 表示當前控制項的左上方加上50px;

     · 百分數 50% 表示當前控制項的50%;

     · 百分數p 50%p 表示父控制項的50%。

2.在一個動畫集合裡,可以通過設定stratOffset屬性,來實現多個動畫並行和串列的效果。

Frame動畫

Frame動畫的設定檔放在drawable目錄下

<?xml version="1.0" encoding="utf-8"?><animation-list xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/image1" android:duration="50"/> <item android:drawable="@drawable/image2" android:duration="50"/> <item android:drawable="@drawable/image3" android:duration="50"/></animation-list>
// 需要先設定成背景imageView.setBackgroundResource(R.drawable.frame_anim);AnimationDrawable frameAnimation = (AnimationDrawable) imageView.getBackground();frameAnimation.start();

總結

以上就是這篇文章的全部內容了,希望本文的內容能對大家開發Android的時候有所協助,如果有疑問大家可以留言交流。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.