Syeda NoorJaha Azim
Syeda NoorJaha Azim

Reputation: 53

Flip animation is not working in Android

I have been working with the Flip Animation in android. I have tested the animation with image view and it's working correctly with the imageView in both side of animation but I cannot figure how to make it work correctly with TextView on both sides. I have used alpha to setback the preview of the second TextView. When I compile the code, I can see the first textView as expected, after clicking the button, I can even see the preview of the first part of the animation but I don't see the second textView on the view. after Clicking the button again, I can again see that first textView is flipping up.

The code is given below:

Main-Activity.java

import android.animation.AnimatorInflater;
import android.animation.AnimatorSet;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;


public class Card_Show extends ActionBarActivity {

TextView question, answer;
Button check;


boolean isBackVisible = false;  
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_card__show);

    question = (TextView)findViewById(R.id.textviewSyn);
    answer = (TextView)findViewById(R.id.TextViewAnswer);


    check = (Button) findViewById(R.id.check);

    final AnimatorSet setRightOut = (AnimatorSet) AnimatorInflater.loadAnimator(getApplicationContext(),
            R.animator.flight_right_out);

    final AnimatorSet setLeftIn = (AnimatorSet) AnimatorInflater.loadAnimator(getApplicationContext(),
            R.animator.flight_left_in);

    check.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (!isBackVisible) {
                setRightOut.setTarget(question);
                setLeftIn.setTarget(answer);
                setRightOut.start();
                setLeftIn.start();
                isBackVisible = true;
            } else {
                setRightOut.setTarget(answer);
                setLeftIn.setTarget(question);
                setRightOut.start();
                setLeftIn.start();
                isBackVisible = false;
            }
        }
    });
}
}

My Animators :

Flight_left_in:

<set xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Rotate. -->
<objectAnimator
    android:valueFrom="-180"
    android:valueTo="0"
    android:propertyName="rotationY"
    android:interpolator="@android:interpolator/accelerate_decelerate"
    android:duration="500" />

<!-- When the roration reach half of animation, show the card -->
<objectAnimator
    android:valueFrom="0.0"
    android:valueTo="1.0"
    android:propertyName="alpha"
    android:duration="1"
    android:startOffset="250"/>

</set>

Flight Right Out

<set xmlns:android="http://schemas.android.com/apk/res/android">

<!-- Rotate. -->
<objectAnimator
    android:valueFrom="0"
    android:valueTo="180"
    android:propertyName="rotationY"
    android:interpolator="@android:interpolator/accelerate_decelerate"
    android:duration="500" />

<!-- Half-way through the rotation, hide the front card -->
<objectAnimator
    android:valueFrom="1.0"
    android:valueTo="0.0"
    android:propertyName="alpha"
    android:startOffset="250"
    android:duration="1" />
</set>

and the main activity layout

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
android:orientation="vertical"
tools:context="com.zerothtech.greapp.Card_Show">

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:layout_margin="10dp"
    android:id="@+id/linear2"
    android:layout_weight="0.7">

    <!--main wordload-->
    <TextView
        android:id="@+id/textviewSyn"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:textColor="#483D8B"
        android:gravity="center"
        android:background="@drawable/curved_textview"
        android:layout_centerHorizontal="true"
        android:text="Question"
        />
    <TextView
        android:id="@+id/TextViewAnswer"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:textColor="#483D8B"
        android:background="@drawable/curved_textview"
        android:layout_centerHorizontal="true"
        android:gravity="center"
        android:alpha="1"
        android:text="Question\nAnswer"/>
</LinearLayout>


<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:gravity="center"
    android:layout_weight="0.1">

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/check"
        android:background="#fff"
        android:layout_marginRight="10dp"
        android:gravity="center"
        android:text="Check it"
        android:textSize="15dp"
        />


</LinearLayout>
</LinearLayout>

Sorry for this long post. Thank you for helping me out.

Upvotes: 0

Views: 297

Answers (1)

Jago
Jago

Reputation: 155

Your text views are placed in a LinearLayout, that means that your second TextView is out of the screen when it appears (because the first one's height and width is fill_parent). Just change your LinearLayout with a FrameLayout. It should work that way.

Upvotes: 1

Related Questions