开发者

How to slide-in and slide-out the Activity on clicking of button.?

I want to slide-in and slide-out the activity on b开发者_运维问答utton click event.


from 2.1 onwords you will do that. First you will download anim folder from api demos. Then apply like below for every intent.

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


you can use android.widget.ViewFlipper: http://developer.android.com/reference/android/widget/ViewFlipper.html

Simple example: http://r00tsecurity.org/forums/topic/12057-android-viewflipper-example/

Hope it helps


Try this,

With viewflipper u can do this.

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

     }

 });


The following codes worked for me: A -> B (B will slide in)

On activity B:

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

B -> A (B will slide out) on clicked a button of 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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜