Android CircularReveal动画bug

时间:2016-02-27 20:14:32

标签: java android android-animation android-recyclerview circularreveal

RecyclerView被按下时,我使用this非常棒的库在SearchView创建CircularReveal动画,我有一个小错误。动画工作正常,但只有在SearchView首次打开和关闭后才能正常工作。当我打开Activity并按SearchView时,RecyclerView会显示没有CircularReveal动画,当我关闭它并再次打开时,一切正常。

这是我的XML:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/tools"
    xmlns:fab="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/root_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    tools:context=".MapsActivity">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/toolbar">

        <fragment xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:tools="http://schemas.android.com/tools"
            android:id="@+id/map"
            android:name="com.google.android.gms.maps.SupportMapFragment"
            class="com.google.android.gms.maps.MapFragment"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            tools:context="ua.nau.edu.NAU_Guide.MapsActivity"
            tools:layout="@layout/fragment_maps" />

    </RelativeLayout>

    <include
        android:id="@+id/toolbar"
        layout="@layout/toolbar" />

    <io.codetail.widget.RevealFrameLayout
        android:id="@+id/reveal_recycler"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/toolbar">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recyclerview_user_data"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/grey_bg"
            android:visibility="gone" />
    </io.codetail.widget.RevealFrameLayout>
</RelativeLayout>

我的动画方法:

private void revealShow(final View view) {
            // get the center for the clipping circle
            int cx = (view.getLeft() + view.getRight()) / 2;
            int cy = (view.getTop() + view.getBottom()) / 2;

            // get the final radius for the clipping circle
            int dx = Math.max(cx, view.getWidth() - cx);
            int dy = Math.max(cy, view.getHeight() - cy);
            float finalRadius = (float) Math.hypot(dx, dy);

            SupportAnimator animator = ViewAnimationUtils.createCircularReveal(view, cx, cy, 0, finalRadius);
            animator.setInterpolator(new AccelerateDecelerateInterpolator());
            animator.setDuration(300);
            view.setVisibility(View.VISIBLE);
            animator.start();

        }

        private void revealClose(final View view) {
            // get the center for the clipping circle
            int cx = (view.getLeft() + view.getRight()) / 2;
            int cy = (view.getTop() + view.getBottom()) / 2;

            // get the final radius for the clipping circle
            int dx = Math.max(cx, view.getWidth() - cx);
            int dy = Math.max(cy, view.getHeight() - cy);
            float finalRadius = (float) Math.hypot(dx, dy);

            SupportAnimator animator = ViewAnimationUtils.createCircularReveal(view, cx, cy, 0, finalRadius);
            animator.setInterpolator(new AccelerateDecelerateInterpolator());
            animator.setDuration(300);
            animator = animator.reverse();
            animator.start();

            view.postDelayed(new Runnable() {
                @Override
                public void run() {
                    view.setVisibility(View.GONE);
                }
            }, 300);

        }

我的SearchView's OnClickListener

searchView.setOnSearchClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //Show RecyclerView
                revealShow(recyclerView);

                ...
            }
        });

我的SearchView's OnCloseListener

searchView.setOnCloseListener(new SearchView.OnCloseListener() {
            @Override
            public boolean onClose() {
                Log.d(TAG, "OnCloseListener/ onClose() called");

                // Hide keyboard
                if (getCurrentFocus() != null) {
                    methodManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
                }

                // Close RecyclerView & SearchView
                searchView.onActionViewCollapsed();
                revealClose(recyclerView);

                return true;
            }
        });

0 个答案:

没有答案