Закончить циркулярную анимацию в определенном месте просмотра
Я работаю с циркулярной анимацией. Это работает правильно.
Это мой код:
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();
Требование:
Я хочу закончить анимацию кругового раскрытия в определенном виде изображения, которое находится в центре моего родительского макета. Как вы знаете, круговое раскрытие заканчивается полностью по центру. Но я не хочу этого.
Я хочу, чтобы круговая анимация показа была закончена, когда она достигнет границ изображения (которое находится в центре моего родительского макета). Я надеюсь, что вы все поймете мой вопрос.
Расширенная помощь будет оценена. Спасибо!
1 ответ
Если я правильно понял, анимация должна остановиться, как только она достигнет углов вашего центрированного ImageView.
Выполните расчет радиуса (ваши первые 3 строки) для ImageView, а затем передайте полученный радиус в качестве последнего аргумента в createCircularReveal
, который является конечным радиусом. Однако это работает, только если ваш ImageView идеально отцентрирован.