开发者

Having trouble animating listview layout

开发者 https://www.devze.com 2023-01-11 01:40 出处:网络
I want the items in the listv开发者_开发技巧iew to slide in one at a time from left to right. I have the following in res/anim/slide_right.xml

I want the items in the listv开发者_开发技巧iew to slide in one at a time from left to right. I have the following in 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>

And in my onCreate method in my ListActivity I have:

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

When I run it, I get a RuntimeException caused by Unknown layout animation name: set

What am I doing wrong?


I had the same problem and I seem to have solved it. I think this problem is similar to this one: http://groups.google.com/group/android-developers/browse_thread/thread/2266e171b9b0cf17

I have posted my answer over there over here as well (with some edits). You will have to define a second XML file that has a layoutAnimation element in it:

"If you want to apply an animation using android:layoutAnimation (or using loadLayoutAnimation), it seems that you have to define an extra XML file that refers to your animation (scale, set, translate, etc...). You can find an example here: http://developerlife.com/tutorials/?p=343.

For example, your second xml file would look like this (let's call it 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"
/>

You can then refer to this animation in your layout file:

android:layoutAnimation="@anim/example"

(or in your code using loadLayoutAnimation)

"

Hope this helps.

Ciao!


I am not sure if you have already found the soulution but let me tell you the way I found the solution.

Make another Android xml in ur anim folder. Let it be list_layout_controller.xml as below

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

Now, set list_layout_controller.xml (using @anim notation) as the animation as below and run:

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

精彩评论

暂无评论...
验证码 换一张
取 消