查看animation从右到左android

我无法将视图animation放在膨胀的布局中。 我使用了下面的代码片段

pageView.startAnimation(AnimationUtils.loadAnimation(this,R.anim.right_to_left_anim.xml)); 

和XML

 <set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="false"> <translate android:fromXDelta="0%" android:toXDelta="100%" android:fromYDelta="0%" android:toYDelta="0%" android:duration="700"/> </set> 

我有什么遗漏?

谢谢。

Solutions Collecting From Web of "查看animation从右到左android"

这是用于视图的滑动animation的代码。

 1)inFromRightAnimation private Animation inFromRightAnimation() { Animation inFromRight = new TranslateAnimation( Animation.RELATIVE_TO_PARENT, +1.0f, Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f); inFromRight.setDuration(500); inFromRight.setInterpolator(new AccelerateInterpolator()); return inFromRight; } 2)outToLeftAnimation private Animation outToLeftAnimation() { Animation outtoLeft = new TranslateAnimation( Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, -1.0f, Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f); outtoLeft.setDuration(500); outtoLeft.setInterpolator(new AccelerateInterpolator()); return outtoLeft; } 3)inFromLeftAnimation private Animation inFromLeftAnimation() { Animation inFromLeft = new TranslateAnimation( Animation.RELATIVE_TO_PARENT, -1.0f, Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f); inFromLeft.setDuration(500); inFromLeft.setInterpolator(new AccelerateInterpolator()); return inFromLeft; } 4)outToRightAnimation private Animation outToRightAnimation() { Animation outtoRight = new TranslateAnimation( Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, +1.0f, Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f); outtoRight.setDuration(500); outtoRight.setInterpolator(new AccelerateInterpolator()); return outtoRight; } 

现在开始查看animation

 pageView.startAnimation(inFromRightAnimation()); 

谢谢,

如果要在首次创build视图时对其进行animation处理,则需要设置layoutAnimation XML属性或调用setLayoutAnimation()

如果你只是想让你的视图看起来像移动,你需要一个TranslateAnimation ; 看到这个答案: https : onAnimationEnd()另外,如果你想重复animation,然后调用setAnimationListener()onAnimationEnd()只是再次启动animation。

如果您试图永久移动视图,请参阅: http : //www.clingmarks.com/how-to-permanently-move-view-with-animation-effect-in-android/400

我知道你已经接受了答案。 但是我觉得这个回复会对读者有帮助。 您可以尝试从pageView.startAnimation(AnimationUtils.loadAnimation(this,R.anim.right_to_left_anim.xml)); 移除.xml pageView.startAnimation(AnimationUtils.loadAnimation(this,R.anim.right_to_left_anim.xml));