我希望listview中的项目从左到右一次一个地滑动。我在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);
当我运行它时,我会收到由RuntimeException
Unknown layout animation name: set
我做错了什么?
答案 0 :(得分:34)
我有同样的问题,我似乎解决了它。我认为这个问题类似于这个问题:http://groups.google.com/group/android-developers/browse_thread/thread/2266e171b9b0cf17
我也在这里发布了我的答案(有一些编辑)。您必须定义第二个XML文件,其中包含layoutAnimation元素:
“如果你想使用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)
“
希望这会有所帮助。
侨!
答案 1 :(得分:5)
我不确定你是否已经找到了洗液,但让我告诉你我找到解决方案的方式。
在你的动画文件夹中创建另一个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);