layoutAnimation添加到LinearLayout会导

layoutAnimation添加到LinearLayout会导

本文介绍了将android:layoutAnimation添加到LinearLayout会导致FC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在menu.xml中有以下XML,这是我需要设置动画的LinearLayout,因此我使用layoutAnimation属性.如果没有此属性,则布局将无法完美显示,但是设置了此属性后,我会遇到讨厌的强制关闭,而且我不明白为什么:

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:

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>

请帮助!谢谢!

推荐答案

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

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

让上述xml称为anim_controller.xml

lets call the above xml as anim_controller.xml

现在在您的线性布局中使用 android:layoutAnimation ="@ anim/anim_controller"

now in your linear layout use android:layoutAnimation="@anim/anim_controller"

这篇关于将android:layoutAnimation添加到LinearLayout会导致FC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 10:04