我有一个列表视图,它使用自定义适配器来显示我的自定义内容。其布局如下。
<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,以便展开该项目以显示项目文本内容。我知道我应该使用补间动画来展开/折叠每个项目,但我不知道如何做到这一点。
如果您需要更多代码片段,请随时询问。
为此,我构建了一个 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();
}
}
}
我的博客上有这个动画的完整示例应用程序post http://udinic.wordpress.com/2011/09/03/expanding-listview-items/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)