问题
I have the following XML in menu.xml, it's a LinearLayout that I need to animate, so I use the layoutAnimation property. Without this property the layout shows flawlesly, but with this property set I get a nasty forceclose and I don't understand why:
<?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...
anim/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>
Help please! Thanks!
回答1:
You cant add an animation directly to a layout. you have to create one more xml file in your anim folder which points to the animation xml (menu_anim) as below.
<?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"
/>
lets call the above xml as anim_controller.xml
now in your linear layout use
android:layoutAnimation="@anim/anim_controller"
来源:https://stackoverflow.com/questions/16453347/adding-androidlayoutanimation-to-a-linearlayout-causes-fc