Android – ripple effects cannot use shared element transformation and recyclerview

When the ` recyclerview item is clicked to start a detailed activity, I have a shared element transformation, but the ripple effect of item clicking will never be visible

Start activity using shared element transformation

Intent intent = IntentUtils.createDetailsIntent(inspectionListFragment.this.getContext(), record);
Bundle options = ActivityOptionsCompat.makeSceneTransitionAnimation(getActivity(),
                  view, getString(R.string.transition_element)).toBundle();
getActivity().startActivity(intent, options);

I noticed this log message

D/OpenGLRenderer: endAllStagingAnimators on 0x95e86600 (RippleDrawable) with handle 0xaa6c2760

If I delete the conversion, the ripple is valid (I don't see this message)

Delay activity start using handler

If I use the handler with postdelayed to start the activity, the result is mixed. I see ripples, but the transition is not smooth:

    handler.postDelayed(new Runnable() {
        @Override
        public void run() {
            Intent intent = IntentUtils.createDetailsIntent(inspectionListFragment.this.getContext(), record);
            Bundle options = ActivityOptionsCompat.makeSceneTransitionAnimation(getActivity(),
                  view, getString(R.string.transition_element)).toBundle();
            getActivity().startActivity(intent, options);
        }
    }, 200);

Using listview

Please note that using a listview with the same project layout and makescenetransitionanimation works. Unfortunately, this is not appropriate

Project layout

<LinearLayout
    android:background="?android:attr/selectableItemBackground"
    android:clickable="true"
    android:focusable="true"

resolvent:

When I use ImageView as a shared element in the card, I encounter the same problem. I can solve it by using cardview as the source view of shared element transformation (and ripple effect)

<android.support.v7.widget.CardView
    android:id="@+id/itemCard"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="8dp"
    app:cardCornerRadius="@dimen/card_corner_radius"
    app:cardElevation="@dimen/card_elevation"
    android:layout_gravity="center"
    android:clickable="true"
    android:onClick="@{onItemClick}"
    android:foreground="?android:attr/selectableItemBackground"
    >

I'm using data binding, but the shared element change actually just selects a different source view:

// before:
//onItemClickListener.onItemClick(view, getAdapterPosition(), getItemId(), Pair.create((View)b.itemImage, "activity_image"));

// after:
onItemClickListener.onItemClick(view, getAdapterPosition(), getItemId(), Pair.create((View)b.itemCard, "activity_image"));

Before that, I also tried to use short delay postdelayed, but I found that this method adds too much delay to my favorite navigation

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>