最近在做啟動頁動畫的時候碰到一個問題,想讓一個圖檔做淡入效果,以下是animation的檔案
android:duration="1000"
android:fromXDelta="0.0"
android:fromYDelta="0.0"
android:interpolator="@android:anim/accelerate_interpolator"
android:startOffset="1000"
android:fillAfter="true"
android:toXDelta="0.0"
android:toYDelta="-120.0" />
android:duration="1000"
android:fromAlpha="0.0"
android:interpolator="@android:anim/accelerate_interpolator"
android:repeatCount="0"
android:startOffset="1000"
android:toAlpha="1.0" />
這裡做了一個位移和淡入的效果,
然後是調用代碼
Animation welcomeAnimation = AnimationUtils.loadAnimation(ReadyActivity.this, R.anim.animation_welcome);
imageView.setAnimation(welcomeAnimation);
welComeAnimation.startNow;
很簡單的實作 需要注意的是 用imageView.startAnimaiton 沒有效果 用 Animation.startNow 才有效果。原因暫未找到,另外需要在imageView的xml聲明裡面設定它的visible屬性為invisible ,千萬不能設定alpha屬性為0 不然整個控件就無法顯示了。還有一點 如果希望動畫在結束的時候不變回動畫最初的狀态,一定!!!!!!一定要在代碼裡面設定 welComeAnimation.setFillAfter(true); 千萬!!!千萬!!!!不能在xml裡面設定!!!!!!至于為什麼!!!!!!!!!!!不要來問我!!!我也不知道!!!我隻知道我被坑了很久!!!!!!