我想在按钮点击事件中滑入并滑出活动。
答案 0 :(得分:6)
从2.1关键字你会做到这一点。首先,您将从api演示文件下载anim文件夹。然后如下所示适用于每一个意图。
Intent intent = new Intent(Fisrst.this, Second.class);
startActivity(intent);
overridePendingTransition(R.anim.slide_left, R.anim.slide_right);
答案 1 :(得分:0)
你可以使用android.widget.ViewFlipper:http://developer.android.com/reference/android/widget/ViewFlipper.html
简单示例: http://r00tsecurity.org/forums/topic/12057-android-viewflipper-example/
希望有所帮助
答案 2 :(得分:0)
试试这个,
使用viewflipper你可以做到这一点。
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();
}
});
答案 3 :(得分:0)
以下代码对我有用: A - > B(B将滑入)
活动B:
protected void onCreate(Bundle savedInstanceState) {
//do something...
view.startAnimation(AnimationUtils.loadAnimation(this, R.anim.g_slide_in_right));
}
B - > 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);