I want to use shared element transition from RecyclerView
item to another Activity
, but it's not working. The RecyclerView
is inside a fragment
, and this is onClick
listener of RecyclerView
item
@Override
public void onProductItemClick(int pos, PromoORProduct promoORProduct, ImageView shareImageView) {
Intent intent = new Intent(getActivity(), ProductPreviewAct_.class);
intent.putExtra("OBJECT", promoORProduct);
intent.putExtra(ProductPreviewAct.SMALL_IMAGE_TRANSITION_NAME, "small_img" + pos);
ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(getActivity(), shareImageView, "small_img" + pos);
getActivity().startActivity(intent, options.toBundle());
}
listener is called from onBindViewHolder of my adapter
@Override
public void onBindViewHolder(final RecyclerView.ViewHolder holder, int position) {
if (holder instanceof ProductsViewHolder) {
final PromoORProduct user = items.get(position);
ProductsViewHolder userViewHolder = (ProductsViewHolder) holder;
ViewCompat.setTransitionName(userViewHolder.imgSmall, "small_img"+position);
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
productsItemClickListener.onProductItemClick(holder.getAdapterPosition(), user, ((ProductsViewHolder) holder).imgSmall);
}
});
userViewHolder.bind(user, this);
} else if (holder instanceof LoadingViewHolder) {
LoadingViewHolder loadingViewHolder = (LoadingViewHolder) holder;
loadingViewHolder.progressBar1.setIndeterminate(true);
}
}
in my called activity's onCreate
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_product_preview);
imgSmall = findViewById(R.id.imgSmall2);
Bundle extras = getIntent().getExtras();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().setSharedElementEnterTransition(TransitionInflater.from(this).inflateTransition(R.transition.shared_element_transaction));
String imageTransitionName = extras.getString(SMALL_IMAGE_TRANSITION_NAME);
imgSmall.setTransitionName(imageTransitionName);
}
}
the output is weird, the image is fading out in the fragment and popping in the called activity's imageview and when exit the same. Any ideas... Thanx a lot
After days of struggle found it, in case anyone else has similar problem...
Check your manifes's application
I had set android:hardwareAccelerated="false"
Removed it and it all works like a charm