2011-06-30 66 views
3

我有一个横向的活动。当我按下时,它会转到纵向视图。我想创建一个从左到右的过渡。我试图overridePendingTransition(anim.slide_in_left,anim.slide_out_right); ..还是过渡不correct.pls帮助从横向视图到纵向视图的Android过渡

回答

0

尝试用下面的代码

import android.app.Activity; 
import android.os.Bundle; 
import android.view.animation.AccelerateInterpolator; 
import android.view.animation.Animation; 
import android.view.animation.AnimationUtils; 
import android.view.animation.TranslateAnimation; 
import android.widget.Button; 
import android.widget.ImageView; 
import android.widget.ViewFlipper; 

public class TeeenAni extends Activity { 

ViewFlipper flipper; 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 
    ImageView image = (ImageView) findViewById(R.id.ImageView01); 
    Animation hyperspaceJump = 
    AnimationUtils.loadAnimation(this, R.anim.); 
    image.startAnimation(hyperspaceJump); 
    flipper = (ViewFlipper) findViewById(R.anim.hyperspace_jump); 

    Button button1 = (Button) findViewById(R.id.Button01); 

    Button button2 = (Button) findViewById(R.id.Button02); 
} 
    private Animation inFromRightAnimation() { 


     Animation inFromRight = new TranslateAnimation(
       Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 
       0.0f, Animation.RELATIVE_TO_SELF, -1.0f, 
       Animation.RELATIVE_TO_SELF, 0.0f); 

     inFromRight.setDuration(500); 
     inFromRight.setInterpolator(new AccelerateInterpolator()); 
     return inFromRight; 
    } 

    private Animation outToLeftAnimation() { 

     Animation outtoLeft = new TranslateAnimation(
       Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 
       0.0f, Animation.RELATIVE_TO_SELF, -1.0f, 
       Animation.RELATIVE_TO_SELF, 0.0f); 
     outtoLeft.setDuration(500); 
     outtoLeft.setInterpolator(new AccelerateInterpolator()); 
     return outtoLeft; 
    } 

    private Animation inFromLeftAnimation() { 

     Animation inFromLeft = new TranslateAnimation(
       Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 
       0.0f, Animation.RELATIVE_TO_SELF, -1.0f, 
       Animation.RELATIVE_TO_SELF, 0.0f); 
     inFromLeft.setDuration(500); 
     inFromLeft.setInterpolator(new AccelerateInterpolator()); 
     return inFromLeft; 
    } 

    private Animation outToRightAnimation() { 

     Animation outtoRight = new TranslateAnimation(
       Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 
       0.0f, Animation.RELATIVE_TO_SELF, -1.0f, 
       Animation.RELATIVE_TO_SELF, 0.0f); 
     outtoRight.setDuration(500); 
     outtoRight.setInterpolator(new AccelerateInterpolator()); 
     return outtoRight; 
    } 
+0

是有任何其他方式比使用动画......这当我们从纵向视图移到纵向视图时,工作正常。 – ShineDown

+0

你能显示你的代码吗? –

相关问题