Android中的動畫效果

2021-07-22 04:24:58 字數 2958 閱讀 7700

alphaanimation animation = new alphaanimation(0,1);

animation.setduration(1000);

view.startanimation(animation);

從0不顯示到1全顯示

rotateanimation animation = new rotateanimation(0,360, animation.relative_to_self,0.5f, animation.relative_to_self,0.5f);

animation.setduration(1000);

view.startanimation(animation);

translateanimation animation = new translateanimation(0,200,0,300);

animation.setduration(1000);

view.startanimation(animation);

從原來的位置x軸移動200,y軸移動300

scaleanimation animation = new scaleanimation(0,2,0,2);

animation.setduration(1000);

view.startanimation(animation);

animationset as = new animationset(true);//是否共享插補器

as.setduration(1000);

alphaanimation aa = new alphaanimation(0, 1);

aa.setduration(1000);

as.addanimation(aa);

translateanimation ta = new translateanimation(0, 100, 0, 200);

ta.setduration(1000);

as.addanimation(ta);

view.startanimation(as);

由於android3.0之前已有的補間動畫改變的只是顯示,並不能響應事件。所以在3.0之後提出了乙個新的動畫框架animator。

objectanimator animator = objectanimator.offloat(btntest,"translationy",300);

animator.setduration(3000);

animator.start();

objectanimator 操作的屬性必須有get,set方法。如果沒有,底層是通過反射改變的值,如果沒有get,set就會無法出現想要的效果。所以就會用到包裝類。

private view mtargetview;

private

int width;

public

this.mtargetview =mtargetview;

}public

intgetwidth()

public

void

setwidth(int width)

}

valueanimator animator = valueanimator.offloat(0,100);

animator.settarget(btntest);

animator.setduration(3000);

animator.start();

animator.addupdatelistener(new valueanimator.animatorupdatelistener()

});

把準備好的放進專案res/ drawable下。

在專案的drawable資料夾下面定義動畫xml檔案,檔名稱可以自定義。當然也可以採用編碼方式定義動畫效果(使用animationdrawable類)。

「1.0」encoding=」utf-8」?>

「android:oneshot=」false」>

「@drawable/zzlx1」android:duration=」200」/>

「@drawable/zzlx2」android:duration=」200」/>

「@drawable/zzlx3」android:duration=」200」/>

「@drawable/zzlx4」android:duration=」200」/>

「@drawable/zzlx5」android:duration=」200」/>

「@drawable/zzlx6」android:duration=」200」/>

「@drawable/zzlx7」android:duration=」200」/>

「@drawable/zzlx8」android:duration=」200」/>

**分析:

在xml中定義好幀動畫之後就可以將其設定到view上了,請看下面**:

//第一步將animation-list設定為imageview的背景

imgshow.setbackgroundresource(r.drawable.framelist);

//第二步獲取imagview的背景並將其轉換成animationdrawable

animationdrawableanimationdrawable=(animationdrawable)imgshow.getbackground();

animationdrawable.start();

有一點需要強調的是:啟動frame動畫的**animationdrawable.start();不能應用在oncreate()方法中,因為在oncreate()中animationdrawable還沒有完全的與imageview繫結。在oncreate()中啟動動畫,只能看到第一張。

android動畫效果

這兩天接觸到一些android特效,例如抖動,平移,轉動等等。標籤可以定義一些動畫效果,可以寫乙個anim的xml來定義動畫的屬性。以下是一些常見的android動畫屬性 平移動畫 duration 持續時間 fromxdelta 屬性為動畫起始時 x座標上的位置 toxdelta 屬性為動畫結束時...

android 動畫效果

animations 一 animations 介紹animations 是乙個實現 android ui 介面動畫效果的 api,animations 提供了一系列的動畫效果,可以進行旋轉 縮放 淡入淡出等,這些效果可以應用在絕大多數的控制項中。二 animations 的分類animations...

Android 彈簧動畫效果

rebound 通過胡克定律,實現的乙個類似 彈簧 動畫效果的第三方工具包,由facebook退出,於2013年10月正式發布,旨在解決笨重 緩慢的傳統流動網路介面。先上幾張效果圖 特點 rebound 可以使你的動畫看起來像真實自然,像真實世界物理運動 rebound 不是乙個物理引擎庫,但是re...