我在单个列表项的动画中遇到问题。如何在点击单个项目时获得翻转视图并获取项目背面的详细信息?
答案 0 :(得分:0)
创建列表行项目,如下所示
<RelativeLayout
android:id="@+id/rellay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginTop="20dp"
android:layout_centerHorizontal="true" >
<TextView
android:id="@+id/back"
android:layout_width="300dp"
android:layout_height="200dp"
android:background="@drawable/linearlayoutshape"
android:gravity="center"
android:text="BACK"
android:textAppearance="@android:style/TextAppearance.Large"
/>
<TextView
android:id="@+id/front"
android:layout_width="300dp"
android:layout_height="200dp"
android:background="@drawable/linearlayoutshape"
android:gravity="center"
android:text="FRONT"
android:textAppearance="@android:style/TextAppearance.Large" />
在这种情况下,我习惯将textView作为Front和Back。 现在在适配器中添加此方法..
public void flip(final View front, final View back, final int duration)
{
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
AnimatorSet set = new AnimatorSet();
set.playSequentially(
ObjectAnimator.ofFloat(front, "rotationY", 90).setDuration(duration / 2),
ObjectAnimator.ofInt(front, "visibility", View.GONE).setDuration(0),
ObjectAnimator.ofFloat(back, "rotationY", -90).setDuration(0),
ObjectAnimator.ofInt(back, "visibility", View.VISIBLE).setDuration(0),
ObjectAnimator.ofFloat(back, "rotationY", 0).setDuration(duration / 2));
set.start();
} else
{
front.animate().rotationY(90).setDuration(duration / 2)
.setListener(new AnimatorListenerAdapter()
{
@Override
public void onAnimationEnd(Animator animation) {
front.setVisibility(View.GONE);
back.setRotationY(-90);
back.setVisibility(View.VISIBLE);
back.animate().rotationY(0).setDuration(duration / 2).setListener(null);
}
});
}
}
现在点击行项目只需调用像
这样的翻转方法flip(txtFront, txtBack, DURATION);
它将添加翻转动画并使txtBack可见并隐藏txtFront