MIL*_*L3S 5 animation android listview collapse
我有一个列表视图,它使用自定义适配器来显示我的自定义内容.它的布局如下.
<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>
Run Code Online (Sandbox Code Playgroud)
我希望listview只显示带有ids itemimage和项目描述的视图,保持itemtext隐藏.我们的想法是在列表的每个项目上都有一个onclicklistener,以便扩展该项目,以便显示itemtext内容.我知道我应该使用补间动画来扩展/折叠每个项目,但我无法弄清楚如何做到这一点.
任何人都可以帮助我吗?如果您需要更多代码段,请随时提出.
提前致谢.
为此,我构建了一个Animation类,它将边距设置为负值,使项目消失.
动画看起来像这样:
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();
}
}
}
Run Code Online (Sandbox Code Playgroud)
我在博客文章中有一个完整的动画示例应用程序