用动画展开 ListView 项目 [英] Expand ListView item with animation

查看:28
本文介绍了用动画展开 ListView 项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 ListView.最初,ListView 包含一些数据.当用户点击一个项目时,另一个布局将动态添加到该项目,因此它的高度会增加.

I have a ListView. Initially, the ListView contains some data. When the user clicks on an item, another layout will be dynamically added to that item so it's height will be increased.

现在,当项目的高度增加时,它会立即显示修改后的项目.但是,我想要的是将其设置为动画,以便逐渐增加项目的高度.

Right now, when the item's height is increased, it shows the modified item instantly. However, what I want is for this to be animated so it increases the item's height gradually.

推荐答案

我想我正在寻找与被问到的相同的方法,我正在寻找一种在显示一些新内容时为列表视图项的扩展设置动画的方法(我只是将某些视图的可见性从 GONE 更改为 VISIBLE).我使用了 mirroredAbstraction 的答案来帮助我应用翻译动画(我不想要旋转动画):

I think I was looking for the same as was asked, I was looking for a way to animate the expanding of the listview item as some new content is shown (I was just changing the visibility on some views from GONE to VISIBLE). I had used the answer by mirroredAbstraction to help me apply a translate animation (I didn't want a rotate animation):

<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/linear_interpolator"
android:fromYDelta="0"
android:toYDelta="-100%p"
android:duration="500"   
/>

到每个视图.它创建了一个很好的效果,但仔细观察,列表视图项实际上突然扩展到所需的整个大小,然后动画将视图放置到位.但我想要的是随着视图变得可见,列表视图项会逐渐减小的效果.

to each of the views. It create a nice effect, but looking closely, the listview item was actually suddenly expanding to the entire size that would be needed, then the animation dropped the views into place. But what I wanted was the effect of the listview item growing down as the views come into visibility.

我在这里找到了我想要的东西:expanding-listview-items

I found exactly what I was looking for here: expanding-listview-items

博主有他的github示例的链接,在这里:ExpandAnimationExample

The blogger has a link to his github sample, here: ExpandAnimationExample

如果你发现这些网站不见了,请通知我,我会提供我的副本.

If you find these sites gone, please inform me and I will make my copy available.

他在内容上设置了一个负边距以使其可见,并将可见性设置为GONE:

he put a negative margin on the content to come into visibility as well as setting visibility to GONE:

android:layout_marginBottom="-50dip"

并编写了一个操作底部边距的动画:

and wrote an animation manipulating the bottom margin:

public class ExpandAnimation extends Animation {
...
    @Override
    protected void applyTransformation(float interpolatedTime, Transformation t) {
        super.applyTransformation(interpolatedTime, t);

        if (interpolatedTime < 1.0f) {

            // Calculating the new bottom margin, and setting it
            mViewLayoutParams.bottomMargin = mMarginStart
                    + (int) ((mMarginEnd - mMarginStart) * interpolatedTime);

            // Invalidating the layout, making us seeing the changes we made
            mAnimatedView.requestLayout();
        }
        ...
    }
}

而且看起来很不错.我找到了他对这个 SO(可能重复?)问题的回答:

and it looks very nice. I found his answer to this SO (possible duplicate?) question:

按顺序向 ListView 添加动画展开/折叠内容

另外,如果你知道做同样事情的另一种方法,请告诉我.

Also, please let me know if you know another way to do the same thing.

这篇关于用动画展开 ListView 项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆