2013-01-03 16 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

1つのビューをアニメーション化するときに、左から右にスライドし、右から左にスライドします。 – 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));

関連する問題