【问题标题】:Circular Reveal Animation not working in the first call循环显示动画在第一次通话中不起作用
【发布时间】:2020-04-05 12:46:20
【问题描述】:

我需要在 2 个片段之间的过渡完成后实现一个圆形显示动画,以便 ImageButton (android:id="@+id/update_profile_pic") 将显示一个漂亮的动画

问题是它不能正常工作:

setEnterSharedElementCallback(new SharedElementCallback() {
        Handler handler = new Handler();

        @Override
        public void onSharedElementEnd(List<String> sharedElementNames,
                                       List<View> sharedElements,
                                       List<View> sharedElementSnapshots) {
            handler.postDelayed(new Runnable() {
                @Override
                public void run() {

                    update_profile_pic.setVisibility(View.GONE);
                    // get the center for the clipping circle
                    int cx = update_profile_pic.getWidth() / 2;
                    int cy = update_profile_pic.getHeight() / 2;

                    // get the final radius for the clipping circle
                    float finalRadius = (float) Math.hypot(cx, cy);

                    // create the animator for this view (the start radius is zero)
                    Animator anim = ViewAnimationUtils.createCircularReveal(update_profile_pic, cx, cy, 0f, finalRadius);

                    // make the view visible and start the animation
                    update_profile_pic.setVisibility(View.VISIBLE);
                    anim.start();
                }
            }, 600);
        }
    });

当我在按钮单击侦听器中尝试此动画时,需要单击按钮两次才能使动画正常工作

布局是这样的:

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_simple_two"
    android:layout_gravity="center_horizontal"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    tools:context=".FragmentB"
    xmlns:app="http://schemas.android.com/apk/res-auto">

<com.mikhaellopez.circularimageview.CircularImageView
    android:id="@+id/profile_picture"
    android:clickable="false"
    android:src="@drawable/roni"
    app:civ_border_color="@color/fadedText"
    app:civ_border_width="0.1dp"
    android:layout_width="260dp"
    android:layout_height="260dp"
    android:layout_margin="18dp"
    android:transitionName="@string/simple_fragment_transition"/>

<ImageButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:padding="16dp"
    android:scaleType="centerInside"
    android:elevation="3dp"
    android:layout_margin="26dp"
    android:id="@+id/update_profile_pic"
    android:src="@drawable/ic_menu_camera"
    android:background="@drawable/round_button"
    android:backgroundTint="@color/colorAccent"
    app:layout_anchor="@id/profile_picture"
    app:layout_anchorGravity="bottom|right|end"
    android:visibility="gone"/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>

有什么帮助吗?

【问题讨论】:

    标签: android animation fragment shared-element-transition


    【解决方案1】:

    尝试将 ImageButton 的 visibility 设置为 invisible 而不是最初的 gone

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多