我创建了一个将“卡片”翻转到其背面的动画。为了实现这一点,我在正面和背面分别使用了 setRotationYBy() 和 setVisibility()。动画本身工作正常,但是当动画运行时,两张卡片的内容都会消失(并在动画完成后重新出现)。cardFront.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
final Runnable moveMapDown = new Runnable() {
public void run() {
map.animate().y(0);
}
};
final Runnable flipCard2 = new Runnable() {
public void run() {
cardBack.setVisibility(View.VISIBLE);
cardFront.setVisibility(View.INVISIBLE);
currentFront = false;
CardBack.animate().rotationYBy(90).setInterpolator
(new DecelerateInterpolator()).withEndAction(moveMapDown).setDuration(300);
cardFront.setRotationY(180);
}
};
Runnable flipCard = new Runnable() {
public void run() {
cardBack.setRotationY(-90);
cardFront.animate().rotationYBy(90).setInterpolator
(new AccelerateInterpolator()).withEndAction(flipCard2).setDuration(300);
}
};
map.animate().y(-200).withEndAction(flipCard);
}
});
XML-Layout 的背面(正面几乎相同)。
<RelativeLayout
android:id="@+id/back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/imageView1"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:layout_centerVertical="true"
android:layout_marginTop="-18dp"
android:background="@drawable/bgpatch"
android:paddingBottom="16dp"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:paddingTop="6dp"
android:visibility="invisible" >
<RelativeLayout
android:layout_width="300dp"
android:layout_height="288dp"
android:background="@drawable/dayplan_element_bg" >
<RelativeLayout
android:id="@+id/background"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/dayplan_element_bg"
android:paddingBottom="2dp"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:paddingTop="2dp" >
<TextView
android:id="@+id/backTitle"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:layout_centerVertical="true"
android:gravity="center"
android:text="zusätzliche Informationen"
android:textAppearance="?android:textAppearanceLarge"
android:textColor="@android:color/primary_text_dark"
android:textSize="30sp"
android:textStyle="italic" />
</RelativeLayout>
<View
android:id="@+id/view1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="-1dp"
android:background="@drawable/shadow" />
</RelativeLayout>
</RelativeLayout>