亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Android動(dòng)畫之TranslateAnimation用法案例詳解

 更新時(shí)間:2021年08月27日 14:58:06   投稿:xusong  
這篇文章主要介紹了Android動(dòng)畫之TranslateAnimation用法案例詳解,本篇文章通過簡(jiǎn)要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下

我們?cè)趯?shí)際的開發(fā)過程中,有很多地方需要使用TranslateAnimation,本文是愛站技術(shù)頻道小編為大家做的簡(jiǎn)單介紹,下面是詳解Android 動(dòng)畫之TranslateAnimation應(yīng)用的參數(shù)說明,希望對(duì)你學(xué)習(xí)這方面知識(shí)有幫助!

android中提供了4中動(dòng)畫:

AlphaAnimation 透明度動(dòng)畫效果
ScaleAnimation 縮放動(dòng)畫效果
TranslateAnimation 位移動(dòng)畫效果
RotateAnimation 旋轉(zhuǎn)動(dòng)畫效果

本節(jié)講解TranslateAnimation動(dòng)畫,TranslateAnimation比較常用,比如QQ,網(wǎng)易新聞菜單條的動(dòng)畫,就可以用TranslateAnimation實(shí)現(xiàn),
通過TranslateAnimation(float fromXDelta, float toXDelta, float fromYDelta, float toYDelta) 來定義動(dòng)畫

參數(shù)說明:

float fromXDelta 動(dòng)畫開始的點(diǎn)離當(dāng)前View X坐標(biāo)上的差值
float toXDelta 動(dòng)畫結(jié)束的點(diǎn)離當(dāng)前View X坐標(biāo)上的差值
float fromYDelta 動(dòng)畫開始的點(diǎn)離當(dāng)前View Y坐標(biāo)上的差值
float toYDelta 動(dòng)畫開始的點(diǎn)離當(dāng)前View Y坐標(biāo)上的差值

常用方法:

animation.setDuration(long durationMillis);//設(shè)置動(dòng)畫持續(xù)時(shí)間
animation.setRepeatCount(int i);//設(shè)置重復(fù)次數(shù)
animation.setRepeatMode(Animation.REVERSE);//設(shè)置反方向執(zhí)行

Xml屬性:

android:duration:運(yùn)行動(dòng)畫的時(shí)間
android:repeatCount:定義動(dòng)畫重復(fù)的時(shí)間

代碼:

public class MainActivity extends Activity {
    ImageView image;
    Button start;
    Button cancel;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        image = (ImageView) findViewById(R.id.main_img);
        start = (Button) findViewById(R.id.main_start);
        cancel = (Button) findViewById(R.id.main_cancel);
        /** 設(shè)置位移動(dòng)畫 向右位移150 */
        final TranslateAnimation animation = new TranslateAnimation(0, 150,0, 0);
        animation.setDuration(2000);//設(shè)置動(dòng)畫持續(xù)時(shí)間
        animation.setRepeatCount(2);//設(shè)置重復(fù)次數(shù)
        animation.setRepeatMode(Animation.REVERSE);//設(shè)置        反方向執(zhí)行
        start.setOnClickListener(new OnClickListener() {
            public void onClick(View arg0) {
                image.setAnimation(animation);
                /** 開始動(dòng)畫 */
                animation.startNow();
            }
        });
        cancel.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                /** 結(jié)束動(dòng)畫 */
                animation.cancel();
            }
        });
    }
}

效果:

到此這篇關(guān)于Android動(dòng)畫之TranslateAnimation用法案例詳解的文章就介紹到這了,更多相關(guān)Android動(dòng)畫之TranslateAnimation用法內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論