android縮放動畫的兩種實現方法

來源:互聯網
上載者:User

標籤:color   rac   ref   對象   java   ace   .com   image   div   

在android開發。我們會常常使用到縮放動畫,普通情況下縮放動畫有兩種實現方式。一種是直接通過java代碼去實現,第二種是通過設定檔實現動畫,以下是兩種動畫的基本是用法:

Java代碼實現:

//建立縮放動畫對象Animation animation = new ScaleAnimation(0, 1.0f, 0f, 1.0f);animation.setDuration(1500);//動畫時間animation.setRepeatCount(3);//動畫的反覆次數animation.setFillAfter(true);//設定為true,動畫轉化結束後被應用imageView1.startAnimation(animation);//開始動畫

通過設定檔實現:

1、首先要在res檔案夾下建立一個anim檔案,在anim建立一個scale.xml檔案例如以下:

<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android">    <scale         android:duration="1500"        android:fillAfter="true"        android:fromXScale="0.0"        android:fromYScale="0.0"        android:interpolator="@android:anim/accelerate_decelerate_interpolator"        android:pivotX="0%"        android:pivotY="50%"        android:toXScale="1.0"        android:toYScale="1.0"        /></set>

2、載入動畫:

Animation animation = AnimationUtils.loadAnimation(this, R.anim.scale);imageView1.startAnimation(animation);//開始動畫
案例:http://download.csdn.net/detail/u013043346/9374204

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.