Reputation:
I am working with Circular reveal animation. Its working properly.
This is my code:
int cx = (int) (first_layout.getMeasuredWidth() / 2f);
int cy = (int) (first_layout.getMeasuredHeight() / 2f);
float radius = (float) Math.sqrt(cx * cx + cy * cy);
Animator anim = ViewAnimationUtils.createCircularReveal(first_layout, cx, cy, radius, 0);
// make the view invisible when the animation is done
anim.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
first_layout.setVisibility(View.GONE);
linear_animation.setVisibility(View.VISIBLE);
final ObjectAnimator logo_left = ObjectAnimator.ofFloat(logo_splash, "translationX", Utils.convertDpToPixel((logo_width / 2) * -1, MainSplashActivity.this));
final ObjectAnimator anim_right = ObjectAnimator.ofFloat(logo_text, "translationX", Utils.convertDpToPixel(text_width / 2, MainSplashActivity.this));
final AnimatorSet animSet_left = new AnimatorSet();
logo_left.setDuration(500);
anim_right.setDuration(500);
animSet_left.setInterpolator(new LinearInterpolator());
animSet_left.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animator) {
logo_text.setVisibility(View.VISIBLE);
}
@Override
public void onAnimationEnd(Animator animator) {
linear_animation.clearAnimation();
Intent intent = new Intent(MainSplashActivity.this, SplashActivity.class);
Pair<View, String> pair1 = Pair.create((View) logo_splash, "MyImage");
Pair<View, String> pair2 = Pair.create((View) logo_text, "logoText");
Bundle options = ActivityOptionsCompat.makeSceneTransitionAnimation(MainSplashActivity.this, pair1, pair2).toBundle();
startActivity(intent, options);
}
@Override
public void onAnimationCancel(Animator animator) {
}
@Override
public void onAnimationRepeat(Animator animator) {
}
});
animSet_left.playTogether(logo_left, anim_right);
animSet_left.start();
}
});
anim.setDuration(1500);
anim.start();
Requirement :
I want to finish circular reveal animation at specific imageview which is in center of my parent layout. As you know that circular reveal finishes with fully centered. But i don't want that.
I want that circular reveal animation should be finished when it will reach the bounds of imageview(which is in center of my parent layout.). I hope all of you will understand my question.
Advanced help would be appreciated. Thanks!
Upvotes: 0
Views: 541
Reputation: 4823
If I understood correctly, the animation should stop as soon as it reaches the corners of your centered ImageView.
Do the radius calculation (your first 3 lines) for the ImageView as well and pass the resulting radius as last argument in createCircularReveal
,
which is the end radius.
However this only works if your ImageView is perfectly centered.
Upvotes: 0