【问题标题】:Adding android:layoutAnimation to a LinearLayout causes FC将 android:layoutAnimation 添加到 LinearLayout 会导致 FC
【发布时间】:2013-05-03 10:21:18
【问题描述】:

我在 menu.xml 中有以下 XML,它是我需要动画的 LinearLayout,所以我使用 layoutAnimation 属性。没有这个属性,布局显示完美,但是有了这个属性集,我得到了一个讨厌的 forceclose,我不明白为什么:

<?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>

请帮忙!谢谢!

【问题讨论】:

    标签: android-animation forceclose


    【解决方案1】:

    您不能将动画直接添加到布局中。您必须在 anim 文件夹中再创建一个 xml 文件,该文件指向下面的动画 xml (menu_anim)。

    <?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"

    【讨论】:

    • 它不适用于 标签小部件,知道吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-09-15
    • 2016-03-18
    • 2016-08-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多