android animation動畫效果的兩種實現方式

來源:互聯網
上載者:User

標籤:android   動畫   animation   淡出效果   

animation動畫效果兩種實現方式注:此例為AlphaAnimation效果,至於其他效果,換一下對象即可。1、.java檔案 代碼控制 添加並且開始animation動畫
//添加動畫效果AlphaAnimation animation = new AlphaAnimation(0.3f, 1.0f);//設定次效果的期間animation.setDuration(2000);//設定動畫的監聽事件animation.setAnimationListener(new AnimationListener() {@Overridepublic void onAnimationStart(Animation animation) {//動畫開始監聽事件//do something...}@Overridepublic void onAnimationRepeat(Animation animation) {}@Overridepublic void onAnimationEnd(Animation animation) {//動畫結束監聽事件//do something...}});//開始動畫view.startAnimation(animation);

2、.xml檔案   代碼載入xml  開始動畫alpha_out.xml  淡出效果
<?xml version="1.0" encoding="utf-8"?><!-- android:duration="@android:integer/config_mediumAnimTime" --><set xmlns:android="http://schemas.android.com/apk/res/android" ><alpha android:fromAlpha="1.0" android:toAlpha="0" android:duration="500"/> <!-- 透明度控制動畫效果 alpha        浮點型值:        fromAlpha 屬性為動畫起始時透明度        toAlpha   屬性為動畫結束時透明度        說明:         0.0表示完全透明        1.0表示完全不透明                     以上值取0.0-1.0之間的float資料類型的數字                長整型值:        duration  屬性為動畫期間        說明:                          時間以毫秒為單位--></set>

代碼載入xml:
屬性:
private Animation anim;private AnimationListener animLis;
載入:
//初始化動畫監聽事件AnimationListeneranimLis = new AnimationListener() {@Overridepublic void onAnimationStart(Animation arg0) {//動畫開始監聽事件//do something...}@Overridepublic void onAnimationRepeat(Animation arg0) {}@Overridepublic void onAnimationEnd(Animation arg0) {//動畫結束監聽事件//do something...tv.setVisibility(View.GONE);}};//載入xmlanim = AnimationUtils.loadAnimation(this, R.anim.alpha_out);//設定監聽事件anim.setAnimationListener(animLis);//開始動畫tv.startAnimation(anim);



android animation動畫效果的兩種實現方式

聯繫我們

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