Java-Android 之動畫的實現

來源:互聯網
上載者:User

標籤:android   style   blog   http   io   color   os   ar   java   

一:顯示隱藏動畫

 

在res目錄下建立一個anim目錄,然後在裡面建立一個alpha.xml檔案

<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android"     android:shareInterpolator="false"    >   <alpha     android:fromAlpha="1.0"    android:toAlpha="0"    android:duration="5000"    ></alpha> </set>

 在顯示的頁面添加一張圖片,然後在MainActivity.java檔案,獲得需要進行動畫的對象,獲得動畫東西那個,將需要的對象添加動畫的對象到動畫的方法

package cn.szy.com;import android.app.Activity;import android.os.Bundle;import android.view.animation.Animation;import android.view.animation.AnimationUtils;import android.widget.ImageView;public class MainActivity extends Activity {    /** Called when the activity is first created. */    @Override    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.main);                Animation animation = AnimationUtils.loadAnimation(this, R.anim.alpha);        animation.setFillAfter(true);        ImageView imageview = (ImageView) this.findViewById(R.id.imageView1);        imageview.startAnimation(animation);    }}

 二:移動動畫

在res目錄下建立一個anim目錄,然後在裡面建立一個translate.xml檔案,然後在動畫裡面擷取了之後載入進去就行了

<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android"     android:shareInterpolator="false"    ><translate     android:fromXDelta="0"    android:fromYDelta="0"    android:toXDelta="100"    android:toYDelta="100"    android:duration="5000"    ></translate>    </set>

 三:旋轉動畫

在res目錄下建立一個anim目錄,然後在裡面建立一個rotate.xml檔案,然後在動畫裡面擷取了之後載入進去就行了

<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android"     android:shareInterpolator="false"    ><rotate     android:fromDegrees="0"        android:toDegrees="180"    android:pivotX="50%"    android:pivotY="50%"    android:duration="5000"    ></rotate>    </set>

 四:放大動畫

在res目錄下建立一個anim目錄,然後在裡面建立一個scale.xml檔案,然後在動畫裡面擷取了之後載入進去就行了

<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android"     android:shareInterpolator="false" ><scale     android:fromXScale="1.0"    android:fromYScale="1.0"    android:toXScale="5.0"    android:toYScale="5.0"    android:pivotX="50%"    android:pivotY="50%"    android:duration="5000"    /></set>

 五:集合動畫,將多個動畫的動作寫到一個檔案中,會按順序和時間進行調用,就能夠實現一些複雜的動畫

<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android"     android:shareInterpolator="false"    ><translate     android:fromXDelta="0"    android:fromYDelta="0"    android:toXDelta="100"    android:toYDelta="100"    android:duration="5000"    ></translate>    <scale     android:fromXScale="1.0"    android:fromYScale="1.0"    android:toXScale="5.0"    android:toYScale="5.0"    android:pivotX="50%"    android:pivotY="50%"    android:duration="5000"    />           <alpha            android:fromAlpha="1.0"           android:toAlpha="0"           android:duration="5000"    /></set>

 

Java-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.