'How can I color Circiural Reveral Animation in Android Activity Transition?
While searching for an animation with a circular transition on the internet, I came across the code below.. but I want to improve it, can you help with this?
- First of all, there is an error that it does not open exactly from the targeted place, but I could not find it.
- I want to color the background during transition
how can I do these? Like this= https://medium.com/@gabornovak/circular-reveal-animation-between-fragments-d8ed9011aec
public class RevealAnimation {
public static final String EXTRA_CIRCULAR_REVEAL_X = "EXTRA_CIRCULAR_REVEAL_X";
public static final String EXTRA_CIRCULAR_REVEAL_Y = "EXTRA_CIRCULAR_REVEAL_Y";
private final View mView;
private final Activity mActivity;
private int revealX;
private int revealY;
public RevealAnimation(View view, Intent intent, Activity activity) {
mView = view;
mActivity = activity;
if (intent.hasExtra(EXTRA_CIRCULAR_REVEAL_X) && intent.hasExtra(EXTRA_CIRCULAR_REVEAL_Y)) {
view.setVisibility(View.INVISIBLE);
revealX = intent.getIntExtra(EXTRA_CIRCULAR_REVEAL_X, 0);
revealY = intent.getIntExtra(EXTRA_CIRCULAR_REVEAL_Y, 0);
ViewTreeObserver viewTreeObserver = view.getViewTreeObserver();
if (viewTreeObserver.isAlive()) {
viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
revealActivity(revealX, revealY);
mView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
});
}
} else {
view.setVisibility(View.VISIBLE);
}
}
public void revealActivity(int x, int y) {
float finalRadius = (float) (Math.max(mView.getWidth(), mView.getHeight()) * 1.1);
Animator circularReveal = ViewAnimationUtils.createCircularReveal(mView, x, y, 0, finalRadius);
circularReveal.setDuration(300);
circularReveal.setInterpolator(new AccelerateInterpolator());
mView.setVisibility(View.VISIBLE);
circularReveal.start();
}
public void unRevealActivity() {
float finalRadius = (float) (Math.max(mView.getWidth(), mView.getHeight()) * 1.1); // I think the error is here but nothing has changed
Animator circularReveal = ViewAnimationUtils.createCircularReveal(
mView, revealX, revealY, finalRadius, 0);
circularReveal.setDuration(300);
circularReveal.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
mView.setVisibility(View.INVISIBLE);
mActivity.finish();
mActivity.overridePendingTransition(0, 0);
}
});
circularReveal.start();
if (MainActivity.getInstance()!=null){
MainActivity.getInstance().mainActivityBottomBar();
}
}
}
StartActivity
int revealX =(mainBottomBarLayout.getLeft() + mainBottomBarLayout.getRight()) / 2;
int revealY =(mainBottomBarLayout.getTop() + mainBottomBarLayout.getBottom()) / 2;
Intent intent = new Intent(MainActivity.this, intentClass);
intent.putExtra(RevealAnimation.EXTRA_CIRCULAR_REVEAL_X, revealX);
intent.putExtra(RevealAnimation.EXTRA_CIRCULAR_REVEAL_Y, revealY);
startActivity(intent);
overridePendingTransition(0, 0);
Style
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
