2013-01-03 7 views
14

팽창 된 레이아웃의보기 애니메이션을 배치 할 수 없습니다. 나는 다음과 같은 코드오른쪽에서 왼쪽으로 애니메이션보기 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> 

어떤 일 전 실종을 사용?

감사합니다.

+0

애니메이션을 실행하려고하면 어떻게됩니까? – WarrenFaith

+0

하나의 뷰에 애니메이션을 적용 할 때 왼쪽에서 오른쪽으로 슬라이딩 한 다음 오른쪽에서 왼쪽으로 슬라이딩합니다. – sd33din90

+0

그리고 대신에 무슨 일이 일어나길 원하나요? – WarrenFaith

답변

55

는 뷰의 슬라이딩 애니메이션의 코드입니다.

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()); 

감사합니다,

+1

하지만보기를 위해 애니메이션을 시작하는 방법. –

+0

yourview.startAnimation (inFromRightAnimation()); –

+0

아주 좋은 대답 – Lokesh

1

처음 생성 된 뷰를 애니메이션하려는 경우 layoutAnimation XML 속성을 설정하거나 setLayoutAnimation()으로 호출해야합니다.

보기가 움직이는 것처럼 보이게하려면 TranslateAnimation이 필요합니다. 이 대답을 참조하십시오 : https://stackoverflow.com/a/4214490/832776 또한 애니메이션을 반복하려면 setAnimationListener()으로 전화하고 onAnimationEnd()에서 애니메이션을 다시 시작하십시오. 영구적으로 볼을 이동하려는 경우

이 참조 : http://www.clingmarks.com/how-to-permanently-move-view-with-animation-effect-in-android/400 여기

1

나는 이미 대답을 수락 한 것을 알고를 애니메이션을 시작합니다. 그러나이 회신은 누군가이 책을 읽는 데 도움이 될 것이라고 생각합니다. 시도해 볼 수 있습니다 .xml, pageView.startAnimation(AnimationUtils.loadAnimation(this,R.anim.right_to_left_anim.xml));