添加动画到ListView以展开/折叠内容 [英] Adding animation to a ListView in order to expand/collapse content

查看:1032
本文介绍了添加动画到ListView以展开/折叠内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个列表视图,它使用自定义适配器,以示我的自定义内容。其布局是以下

I have a list view which uses a custom adapter in order to show my custom content. Its layout is the following.

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1">
        <ImageView
            android:id="@+id/itemimage"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="5"
            android:scaleType="fitCenter"/>
        <TextView
            android:id="@+id/itemdescription"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:padding="10dp"
            android:textSize="16sp"
            android:layout_weight="1"/>
    </LinearLayout>    
    <TextView
            android:id="@+id/itemtext"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:text="TEXT CONTENT"
            android:layout_weight="1"/>
</LinearLayout>    

我想,该列表视图只显示与IDS itemimage和项目描述来看,保持itemtext隐患。 我们的想法是对列表的每个项目添加onclicklistener,为了扩大该项目,以便它显示了itemtext内容。我知道我应该使用补间动画,以展开/折叠每个项目,但我无法弄清楚如何做到这一点。

I would like that the listview only showed the view with the ids itemimage and item description, keeping the itemtext hidden. The idea is to have an onclicklistener on each item of the list, in order to expand that item so it shows the itemtext content. I know I should use Tweening animation in order to expand/collapse each item, but I can't figure out how to do that.

谁能帮我呢?如果您需要更多code片段,随意问。

Can anyone help me with it? If you need more code snippets, feel free to ask.

在此先感谢。

推荐答案

要做到这一点,我建立了一个动漫类,动画边距为负值,使得该项目消失。

To do that, I built an Animation class, which animates the margin to negative values, making the item disappear.

动画看起来是这样的:

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();
    }
}
}

我对这个动画在我的博客发布一个完整的示例应用程序

这篇关于添加动画到ListView以展开/折叠内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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