97干视频,99国产精品懂色,亚洲精品99久久久久中文字幕,伊人五月丁香综合AⅤ,国产精品成人免费999

  您的位置:華清遠見教育科技集團 >> 新聞動態(tài) >> Android資料 >> Android中的四種補間動畫  
 
Android中的四種補間動畫
分享到:

在Android的控件層面上,為了增強界面的感染力,已經(jīng)引入了多種動畫效果,如可以為Activity、對話框、輸入法、子菜單、墻紙等設(shè)置動畫效果,相關(guān)的配置文件實現(xiàn)位于frameworks/base/core/res/res/anim中。

補間動畫即通過對場景里的對象不斷做圖像變換(透明度、平移、縮放、旋轉(zhuǎn))產(chǎn)生動畫效果。針對不同的圖像變換動畫,Android提供了AlphaAnimation、ScaleAnimation、RotateAnimation、TranslateAnimation等四個類支持。

下面是一個補間動畫的具體例子的實現(xiàn):

代碼:補間動畫的實現(xiàn)

package com.miaozl.test;

import android.app.Activity;
    import android.os.Bundle;
    import android.view.animation.Animation;
    import android.view.animation.AnimationUtils;
    import android.widget.ImageView;

public class TweenAnimActivity extends Activity {

        ImageView tweenImage;

        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.animation);
        }
        public void onWindowFocusChanged (boolean hasFocus){

            if(hasFocus){
                tweenImage = (ImageView) findViewById(R.id.anim);
                tweenImage.setImageResource(R.drawable.photo1);
                Animation tweenAnimation = AnimationUtils.loadAnimation(this, R.anim.tweenanim);
                tweenImage.startAnimation(tweenAnimation);
            }
        }
    }

下面是res/anim-hdpi/tweenanim.xml的實現(xiàn):

<?xml version="1.0" encoding="utf-8"?>
    <set xmlns:android="//schemas.android.com/apk/res/android"
        android:shareInterpolator="false">
    <scale
        android:interpolator= "@android:anim/accelerate_decelerate_interpolator"
        android:fromXScale="0.5"
        android:toXScale="1.5"
        android:fromYScale="0.5"
        android:toYScale="1.5"
        android:pivotX="50%"
        android:pivotY="50%"
        android:fillAfter="false"
        android:startOffset="700"
        android:duration="2000"
        android:repeatCount="10"
        />
    </set>

下圖是補間動畫的運行效果。

補間動畫的效果圖

需要注意的是,補間動畫并不只是針對圖像的,它實際上還能支持TextView等視圖對象。

 更多相關(guān)文章

·Android開發(fā)中的人臉檢測技術(shù)
·Android中如何實現(xiàn)圖像瀏覽
·Android圖像旋轉(zhuǎn)源碼分享
·Android中多媒體縮略圖的生成
·Android 圖像縮放之bitmap類