2013-05-09 82 views
0

我在menu.xml中有以下XML,它是一個需要動畫的LinearLayout,所以我使用layoutAnimation屬性。如果沒有這個屬性的佈局顯示flawlesly,但與此屬性的,我得到一個討厭的forceclose,我不明白爲什麼:將android:layoutAnimation添加到LinearLayout會導致FC

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@drawable/bkgrnd" 
    android:layoutAnimation="@anim/menu_anim" <=== adding this results in FC 
...etc... 

動畫/ menu_anim.xml:

<?xml version="1.0" encoding="utf-8"?> 
<set 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shareInterpolator="false"> 
    <alpha 
     android:fromAlpha="0.0" 
     android:toAlpha="1.0" 
     android:duration="500"> 
    </alpha>  

</set> 

請幫助!謝謝!

回答

7

你不能直接添加動畫到佈局。您必須在anim文件夾中創建一個指向動畫xml(menu_anim)的多個xml文件,如下所示。

<?xml version="1.0" encoding="utf-8"?> 
<layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android" 
android:delay="30%" 
android:animation="@anim/menu_anim" 
/> 

可以撥打上面的XML作爲anim_controller.xml

現在在你的線性佈局中使用 android:layoutAnimation="@anim/anim_controller"

相關問題