2011-08-25 84 views

回答

0

试试这个,

随着viewflipper u能做到这一点。

private Animation inFromTopAnimation() { 

Animation inFromTop = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f, 
Animation.RELATIVE_TO_PARENT, -1.0f, Animation.RELATIVE_TO_PARENT, 0.0f 
); 
inFromTop.setDuration(1000); 
inFromTop.setInterpolator(new AccelerateInterpolator()); 
return inFromTop; 
} 
private Animation outToBottomAnimation() { 
Animation outtoBottom = new TranslateAnimation(
    Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f, 
    Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, +1.0f 
); 
outtoBottom.setDuration(1000); 
outtoBottom.setInterpolator(new AccelerateInterpolator()); 
return outtoBottom; 
} 

private Animation outToTopAnimation() { 
Animation inFromTop = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f, 
Animation.RELATIVE_TO_PARENT, +1.0f, Animation.RELATIVE_TO_PARENT, 0.0f 
); 
inFromTop.setDuration(1000); 
inFromTop.setInterpolator(new AccelerateInterpolator()); 
return inFromTop; 
} 
private Animation outFromBottomAnimation() { 
Animation outFromBottom = new TranslateAnimation(
    Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f, 
    Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, -1.0f 
); 
outFromBottom.setDuration(1000); 
outFromBottom.setInterpolator(new AccelerateInterpolator()); 
return outFromBottom; 
} 

/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle savedInstanceState) { 
super.onCreate(savedInstanceState); 
setContentView(R.layout.main); 

flipper = (ViewFlipper) findViewById(R.id.flipper); 

ImageView imgview1 = (ImageView) findViewById(R.id.imageview1); 

Button button2 = (Button) findViewById(R.id.flipback); 

imgview1.setOnClickListener(new View.OnClickListener() { 
    public void onClick(View view) { 
     flipper.setInAnimation(inFromTopAnimation()); 
     flipper.setOutAnimation(outToBottomAnimation()); 
     flipper.showNext();  
    } 
}); 

button2.setOnClickListener(new View.OnClickListener() { 
    public void onClick(View view) { 
     flipper.setInAnimation(outToTopAnimation()); 
     flipper.setOutAnimation(outFromBottomAnimation()); 
     flipper.showPrevious(); 

    } 

}); 
6

从2.1个词你会做到这一点。首先,您将从api演示下载anim文件夹。然后像下面一样申请每个意图。

Intent intent = new Intent(Fisrst.this, Second.class); 
startActivity(intent); 
overridePendingTransition(R.anim.slide_left, R.anim.slide_right); 
+0

Thanx harish ... –

0

以下代码为我工作: A - > B(B将在滑入)

在活性B:

protected void onCreate(Bundle savedInstanceState) { 
    //do something... 
     view.startAnimation(AnimationUtils.loadAnimation(this, R.anim.g_slide_in_right)); 
    } 

乙 - > A(B会滑出) 点击了某个按钮B:

final Handler handler = new Handler(); 
    handler.postDelayed(new Runnable() { 
      @Override 
      public void run() { 
         Intent myIntent = new Intent(B.this.getBaseContext(), A.class); 
         B.this.startActivity(myIntent); 
      } 
     }, 500);