我一直在使用android中的Flip Animation。我已经使用图像视图测试了动画,并且它在动画的两侧都正确地使用了imageView但我无法想象如何使用两侧的TextView使其正常工作。我用alpha来设置第二个TextView的预览。当我编译代码时,我可以看到第一个textView按预期,单击按钮后,我甚至可以看到动画的第一部分的预览,但我没有看到视图上的第二个textView。再次单击该按钮后,我再次看到第一个textView正在翻转。
代码如下:
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;
}
}
});
}
}
我的动画师:
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>
飞行右转
<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>
和主要活动布局
<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>
很抱歉这篇长篇文章。谢谢你帮助我。
答案 0 :(得分:1)
您的文本视图放置在LinearLayout中,这意味着第二个TextView出现时不在屏幕之外(因为第一个TextView的高度和宽度为fill_parent
)。只需使用FrameLayout更改LinearLayout即可。它应该这样工作。