Android Card Flip教程动画无法正常工作

时间:2014-06-04 12:36:35

标签: android android-layout fragment android-animation

我尝试实现教程here中显示的卡片翻转动画,但动画不起作用,我不能为我的生活看到原因。我能帮忙吗?

我的翻盖卡方法:

public void flipCard(View v) {
    if (mShowingFront) {
        getFragmentManager().popBackStack();
        mShowingFront = false;
        return;
    }

    mShowingFront = true;
    getFragmentManager()
            .beginTransaction()
            .setCustomAnimations(
                    R.animator.card_flip_right_in, R.animator.card_flip_right_out,
                    R.animator.card_flip_left_in, R.animator.card_flip_left_out)
            .replace(R.id.container, new CardFrontFragment())
            .addToBackStack(null)

            // Commit the transaction.
            .commit();
}

的onCreate():

    @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.display_cards_activity);
    if (savedInstanceState == null) {
        getFragmentManager()
                .beginTransaction()
                .add(R.id.container, new CardBackFragment())
                .commit();
    }

}

卡片布局文件背面:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/card_display_back_fragment_id"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<LinearLayout
    android:layout_width="500dp"
    android:layout_height="800dp"
    android:layout_centerInParent="true"
    android:background="@drawable/customborder">

    <ImageButton
        android:id="@+id/card_back_image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/exercise_goal_large"
        android:onClick="flipCard"/>

</LinearLayout>

1 个答案:

答案 0 :(得分:1)

嗯,我弄清楚出了什么问题。首先,动画确实在触发,但它们的发生得如此之快,以至于人眼看不见它们。

至于究竟是什么问题:翻转动画的android:startOffset值太小(即1和2),导致动画分别持续1和2毫秒。

相关问题