我想使用从RecyclerView
项目到另一个Activity
的共享元素转换,但它不起作用。 RecyclerView
位于fragment
内,这是onClick
项目的RecyclerView
听众
@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());
}
从我的适配器的onBindViewHolder 调用侦听器
@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);
}
}
在我的被叫活动的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);
}
}
输出很奇怪,图像在片段中淡出并弹出被调用活动的imageview并退出时。有任何想法吗... Thanx很多
答案 0 :(得分:3)
经过几天的挣扎发现它,以防其他人有类似的问题...
检查你的表现的申请
我设置了android:hardwareAccelerated="false"
删除它,它就像一个魅力