Reputation: 1222
I tried implementing the Card Flipping animations shown in the tutorial hereexcept the animations aren't working and I can't for the life of me see why. Can I please get some help?
My Flip Card method:
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();
}
}
Back of card layout file:
<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>
Upvotes: 0
Views: 965
Reputation: 1222
Well, I figured out what was wrong. For one, the animations were indeed triggering but they happened so fast that to the human eye, they're invisible.
As to what was actually the problem: the android:startOffset values of the flipping animations were far too small (namely 1 and 2), resulting in the animations lasting 1 and 2 milliseconds respectively.
Upvotes: 1