Adding android:layoutAnimation to a LinearLayout causes FC

自闭症网瘾萝莉.ら 提交于 2021-02-16 15:10:27

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!