[英]Android Activity Transitions + Animation to reveal loaded activity
[英]Android Reveal Animation to start an Activity
如何在兩個活動之間使用Reveal Animation? 有很多關於如何使用它來啟動Activity內部視圖的信息和示例,但是我想單擊一個按鈕並啟動一個Reveal Animation來打開下一個Activity。 我嘗試在第一個布局中包含第二個布局並將其設置為Invisible,然后在單擊按鈕時顯示它。 但它不能正常工作。 我想知道我是否可以簡單地將Reveal動畫定義為XML,但我不知道該怎么做。 謝謝
Reveal Effect對我的活動和片段成功起作用也應用下面的代碼來設置揭示對活動或片段的影響。 刪除注釋以使用代碼下方的特定動畫表單。
- >在setcontentview之后應用此代碼
rootview = (RelativeLayout) findViewById(R.id.rootview);
rootview.setBackgroundColor(getResources().getColor(R.color.colorAccent));
rootview.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
@Override
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
v.removeOnLayoutChangeListener(this);
/*//BOTTOM RIGHT TO TOP LEFT ANIMATION
int cx = (framelayout.getLeft() + framelayout.getRight());
int cy = (framelayout.getTop() + framelayout.getBottom());
// get the hypothenuse so the radius is from one corner to the other
int radius = (int) Math.hypot(right, bottom);
Animator reveal = ViewAnimationUtils.createCircularReveal(v, cx, cy, 0, radius);
reveal.setInterpolator(new AccelerateDecelerateInterpolator());
reveal.setDuration(600);
reveal.start();*/
/* //LEFT TOP TO BOTTOM RIGHT ANIMATION
int cx1 = 0;
int cy1 = 0;
// get the hypothenuse so the radius is from one corner to the other
int radius1 = (int) Math.hypot(right, bottom);
Animator reveal1 = ViewAnimationUtils.createCircularReveal(v, cx1, cy1, 0, radius1);
reveal1.setInterpolator(new DecelerateInterpolator(2f));
reveal1.setDuration(1000);
reveal1.start();*/
/* //EFFECT START WITH CENTER
float finalRadius = (float) Math.hypot(v.getWidth(), v.getHeight());
int cx1 = (framelayout.getLeft() + framelayout.getRight()) / 2;
int cy1 = (framelayout.getTop() + framelayout.getBottom()) / 2;
Animator anim = ViewAnimationUtils.createCircularReveal(v, cx1, cy1, 0, finalRadius);
anim.setDuration(1000);
anim.setInterpolator(new AccelerateDecelerateInterpolator());
anim.start();*/
//OPEN WITH BOTTOM CENTER
int cx = (rootview.getLeft() + rootview.getRight()) / 2;
int cy = (rootview.getTop() + rootview.getBottom());
// get the hypothenuse so the radius is from one corner to the other
int radius = (int) Math.hypot(right, bottom);
Animator reveal = ViewAnimationUtils.createCircularReveal(v, cx, cy, 0, radius);
reveal.setInterpolator(new AccelerateDecelerateInterpolator());
reveal.setDuration(350);
reveal.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
}
@Override
public void onAnimationEnd(Animator animation) {
// rootview.setBackgroundResource(R.color.white);
}
@Override
public void onAnimationCancel(Animator animation) {
}
@Override
public void onAnimationRepeat(Animator animation) {
}
});
reveal.start();
}
});
- >隱藏顯示效果onBackPressed()
// previously visible view
final View myView = findViewById(R.id.rootview);
// get the center for the clipping circle
int cx = myView.getWidth() / 2;
int cy = myView.getHeight() / 2;
// get the initial radius for the clipping circle
float initialRadius = (float) Math.hypot(cx, cy);
// create the animation (the final radius is zero)
Animator anim =
ViewAnimationUtils.createCircularReveal(myView, cx, cy, initialRadius, 0);
anim.setDuration(50);
// make the view invisible when the animation is done
anim.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
myView.setVisibility(View.INVISIBLE);
}
});
// start the animation
anim.start();
例如,您可以為活動的父布局設置動畫。 這是一個可能對您有幫助的答案。 它在活動中消失,但如果您了解它的完成方式,您可以應用任何動畫。
要取消活動動畫中內置的標准,您可以使用此Intent.FLAG :
intent.setFlag(Intent.FLAG_ACTIVITY_NO_ANIMATION);
當你開始你的活動。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.