【问题标题】:Having trouble animating listview layout动画列表视图布局时遇到问题
【发布时间】:2010-08-10 03:27:45
【问题描述】:

我希望列表视图中的项目从左到右一次滑入一个。我在 res/anim/slide_right.xml 中有以下内容

<?xml version="1.0" encoding="utf-8"?>

<set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_interpolator">
    <translate android:fromXDelta="100%p" android:toXDelta="0" android:duration="150" />
</set>

在我的 ListActivity 的 onCreate 方法中,我有:

LayoutAnimationController controller = AnimationUtils.loadLayoutAnimation(this, R.anim.slide_right);
mList.setLayoutAnimation(controller);

当我运行它时,我得到一个由Unknown layout animation name: set 引起的RuntimeException

我做错了什么?

【问题讨论】:

  • 有趣的是,你的代码对我来说很好用。

标签: android listview layout animation


【解决方案1】:

我有同样的问题,我似乎已经解决了。我觉得这个问题和这个类似:http://groups.google.com/group/android-developers/browse_thread/thread/2266e171b9b0cf17

我也在这里发布了我的答案(进行了一些修改)。您必须定义第二个包含 layoutAnimation 元素的 XML 文件:

“如果您想使用 android:layoutAnimation(或使用 loadLayoutAnimation)应用动画,您似乎必须定义一个额外的 XML 文件来引用您的动画(缩放、设置、翻译等)。你可以在这里找到一个例子:http://developerlife.com/tutorials/?p=343

例如,您的第二个 xml 文件将如下所示(我们称之为 example.xml):

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

然后你可以在你的布局文件中引用这个动画:

android:layoutAnimation="@anim/example"

(或在您的代码中使用 loadLayoutAnimation)

"

希望这会有所帮助。

Ciao!

【讨论】:

    【解决方案2】:

    我不确定你是否已经找到了解决方案,但让我告诉你我找到解决方案的方法。

    在你的 anim 文件夹中创建另一个 Android xml。让它成为 list_layout_controller.xml 如下

    <layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android"
            android:delay="20%"
            android:animationOrder="normal"
            android:animation="@anim/slide_right">
    </layoutAnimation>
    

    现在,将 list_layout_controller.xml(使用@anim 表示法)设置为如下动画并运行:

    LayoutAnimationController controller = AnimationUtils.loadLayoutAnimation(this, R.anim.list_layout_controller); 
    mList.setLayoutAnimation(controller); 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-29
      • 2020-03-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多