下面列出了android.view.animation.TranslateAnimation#RELATIVE_TO_PARENT 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public void translateAnim_java(View view) {
// 2.����TranslateAnimation
TranslateAnimation animation = new TranslateAnimation(
TranslateAnimation.RELATIVE_TO_PARENT, 0,
TranslateAnimation.RELATIVE_TO_PARENT, 0,
TranslateAnimation.RELATIVE_TO_PARENT, 0,
TranslateAnimation.RELATIVE_TO_PARENT, -1f);
animation.setDuration(5000);
// ͣ�����
animation.setFillAfter(true);
// ���ò�ֵ��
animation.setInterpolator(new LinearInterpolator());
// 3.���Ŷ���
iv_rocket.startAnimation(animation);
}
private AnimationSet getEntryAnimation(int inAnimationDuration) {
//In
AnimationSet mInAnimationSet = new AnimationSet(false);
TranslateAnimation mSlideInAnimation = new TranslateAnimation(
TranslateAnimation.RELATIVE_TO_PARENT, 0.0f,
TranslateAnimation.RELATIVE_TO_PARENT, 0.0f,
TranslateAnimation.RELATIVE_TO_SELF, -1.0f,
TranslateAnimation.RELATIVE_TO_SELF, 0.0f);
mSlideInAnimation.setFillAfter(true);
AlphaAnimation mFadeInAnimation = new AlphaAnimation(0.0f, 1.0f);
mFadeInAnimation.setFillAfter(true);
mInAnimationSet.addAnimation(mSlideInAnimation);
mInAnimationSet.addAnimation(mFadeInAnimation);
mInAnimationSet.setDuration(inAnimationDuration);
return mInAnimationSet;
}
void setUpTextBoxArrowAnimation(ImageView textboxArrow) {
TranslateAnimation textBoxArrowAnimation = new TranslateAnimation(
TranslateAnimation.ABSOLUTE, 0f,
TranslateAnimation.ABSOLUTE, 0f,
TranslateAnimation.RELATIVE_TO_PARENT, 0f,
TranslateAnimation.RELATIVE_TO_PARENT, 0.01f);
textBoxArrowAnimation.setDuration(500);
textBoxArrowAnimation.setRepeatCount(-1);
textBoxArrowAnimation.setRepeatMode(Animation.RESTART);
textBoxArrowAnimation.setInterpolator(new LinearInterpolator());
textBoxArrowAnimation.setFillAfter(true);
textboxArrow.setAnimation(textBoxArrowAnimation);
}
private void setUpTextBoxArrowAnimation() {
ImageView textBoxArrow = findViewById(R.id.textbox_box_arrow);
TranslateAnimation textBoxArrowAnimation = new TranslateAnimation(TranslateAnimation.ABSOLUTE, 0f,
TranslateAnimation.ABSOLUTE, 0f,
TranslateAnimation.RELATIVE_TO_PARENT, 0f,
TranslateAnimation.RELATIVE_TO_PARENT, 0.01f);
textBoxArrowAnimation.setDuration(500);
textBoxArrowAnimation.setRepeatCount(-1);
textBoxArrowAnimation.setRepeatMode(Animation.RESTART);
textBoxArrowAnimation.setInterpolator(new LinearInterpolator());
textBoxArrowAnimation.setFillAfter(true);
textBoxArrow.setAnimation(textBoxArrowAnimation);
}
public void setAnim_java(View view) {
// 2.����һ��AnimationSet
AnimationSet set = new AnimationSet(true);
// 3.������������:ƽ�ơ���ת�����š���
// 2.����TranslateAnimation
TranslateAnimation trans = new TranslateAnimation(
TranslateAnimation.RELATIVE_TO_PARENT, 0,
TranslateAnimation.RELATIVE_TO_PARENT, 0,
TranslateAnimation.RELATIVE_TO_PARENT, 0,
TranslateAnimation.RELATIVE_TO_PARENT, -1f);
// 2.����ScaleAnimation
ScaleAnimation scale = new ScaleAnimation(1f, 0.6f, 1f, 0.6f,
ScaleAnimation.RELATIVE_TO_SELF, 0.5f,
ScaleAnimation.RELATIVE_TO_SELF, 0.5f);
// 4.ͨ��set.addAnimtion()
set.addAnimation(trans);
set.addAnimation(scale);
// ��ֵ��
set.setInterpolator(new AccelerateInterpolator());
// ����ʱ��
set.setDuration(2000);
// ����ֹͣ�����
set.setFillAfter(true);
// 5.���Ŷ���
iv_rocket.startAnimation(set);
}