Android開發之自訂動畫

來源:互聯網
上載者:User

 

Android開發之自訂動畫

/*

 *  Android開發之動畫

 *  北京Android俱樂部群:167839253

 *  Created on: 2011-8-23

 *  Author: blueeagle

 *  Email: liujiaxiang@gmail.com

 */

    總結一下關於Android開發下的自訂動畫,主要是四個方面,尺寸,透明度,位置變化和旋轉。動畫需要寫在res的anim目錄下。寫完直接調用就可以了。

       如下所示動畫檔案:

<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android">    <translate android:interpolator="@android:anim/accelerate_decelerate_interpolator"       android:fromYDelta="-100"       android:toYDelta="0"       android:duration="1000"       android:fillEnabled="true"       android:fillAfter="true"       />        <scale android:fromXScale="0.6" android:toXScale="1.0"                android:fromYScale="0.6" android:toYScale="1.0" android:pivotX="50%"                android:pivotY="50%" android:duration="2000" />        <alpha android:interpolator="@android:anim/decelerate_interpolator"                android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="2000" />                        <rotate        android:interpolator="@android:anim/accelerate_decelerate_interpolator"        android:fromDegrees="0"        android:toDegrees="+359"        android:pivotX="50%"        android:pivotY="50%"        android:duration="2000">        </rotate></set>

 

相應說明:

 

fromAlpha為動畫起始時的透明度;

toAlpha為動畫結束時的透明度;

interpolator為制定一個動畫的插入器;

fromXScale為動畫起始時x座標上的伸縮尺寸;

toXScale為動畫結束時x座標上的伸縮尺寸;

fromYScale為動畫起始時y座標上的伸縮尺寸;

toYScale為動畫結束時y座標上的伸縮尺寸;

pivotX和pivotY設定動畫相對於自身的位置;

fillAfter表示動畫的轉換在動畫結束後是否被應用;

fromDegrees為動畫起始時物件的角度;

toDegrees為動畫結束時物件旋轉的角度。

 

在Android開發之popwindow中已經講過了對於彈出框動畫的使用方法。現在記錄一片動畫的開發方法。

      

       只需要三行代碼就可以載入圖片動畫:

           myAnimation = AnimationUtils.loadAnimation(this, R.anim.ani_in);

        myImageView = (ImageView)findViewById(R.id.myImageView);

        myImageView.startAnimation(myAnimation);

需要在xml布局檔案中載入圖片:

    <ImageView    android:id="@+id/myImageView"      android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:src="@drawable/icon"    />

聯繫我們

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