[英]View animation right to left android
我無法為膨脹的布局添加視圖動畫。 我使用了以下代碼片段
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>
我錯過了什么?
謝謝。
這是用於視圖的滑動動畫的代碼。
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;
}
現在在視圖上啟動動畫
pageView.startAnimation(inFromRightAnimation());
謝謝,
如果您在第一次創建視圖時嘗試為視圖設置動畫,則需要設置layoutAnimation
XML屬性或調用setLayoutAnimation()
。
如果你只是想讓你的視圖看起來像是在移動,你需要一個TranslateAnimation
; 請參閱此答案: https : onAnimationEnd()
此外,如果您想重復動畫,則調用setAnimationListener()
並在onAnimationEnd()
再次啟動動畫。
如果您嘗試永久移動視圖,請參閱: 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));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.