2013-05-06 30 views
0

是否可以順利地爲多個按鈕製作淡出動畫?Android:爲多個按鈕製作淡出動畫更加流暢

創建fadeout.xml @ RES /阿尼姆

<?xml version="1.0" encoding="UTF-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android"> 
<alpha 
    android:fromAlpha="1.0" 
    android:toAlpha="0.0" 
    android:interpolator="@android:anim/accelerate_interpolator" 
    android:duration="1500" 
    android:repeatCount="infinite" /> 
</set> 

使用此設置動畫

Animation fadeout = AnimationUtils.loadAnimation(this, R.anim.fadeout); 

,點擊後動畫應用於某些按鈕

public void click (View v){ 
    button1.startAnimation(fadeout); 
    button2.startAnimation(fadeout); 
    button3.startAnimation(fadeout); 
    button4.startAnimation(fadeout); 
    button5.startAnimation(fadeout); 
    button6.startAnimation(fadeout); 
    button7.startAnimation(fadeout); 
    button8.startAnimation(fadeout); 
    button9.startAnimation(fadeout); 
    button10.startAnimation(fadeout); 
    button11.startAnimation(fadeout); 
    button12.startAnimation(fadeout); 
    button13.startAnimation(fadeout); 
    button14.startAnimation(fadeout); 
    button15.startAnimation(fadeout); 
} 

這不是一個當應用到3-5個按鈕時會出現問題,但是當應用於上面的許多按鈕時,它會變得遲緩。

那麼有沒有辦法讓這個動畫應用到許多按鈕沒有laggy?

因爲我需要將這個動畫應用到許多按鈕上,162個按鈕周圍。

我正在使用Galaxy Nexus進行測試。

+1

爲什麼地球上需要單獨應用〜160個按鈕?爲什麼不將它應用到容器視圖? – Cornholio 2013-05-06 10:25:02

+0

所以我需要選擇所有的按鈕幷包裝在容器中?那麼什麼類型的容器?網格佈局?的LinearLayout? – user2341387 2013-05-06 10:29:16

+1

這取決於你 - 有了這麼多按鈕,我認爲你動態地添加它們? – Cornholio 2013-05-06 10:30:17

回答

4

沒必要單獨爲每個按鈕應用動畫;相反,將它們全部粘貼到另一個佈局(即GridLayout)中,然後將動畫應用到該佈局。