我正在尝试在RecyclerView上使用共享元素转换,但它似乎不起作用。
这是我的适配器的一部分,我使用makeSceneTransitionAnimation()
:
public void onBindViewHolder(final BookViewHolder holder, final int position) {
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(context, DetailsActivity.class);
ActivityOptionsCompat optionsCompat = ActivityOptionsCompat.makeSceneTransitionAnimation((Activity)context , holder.smallThumbnail, "thumbnailTransition");
context.startActivity(intent, optionsCompat.toBundle());
}
}
}
答案 0 :(得分:14)
在您的适配器
中holder.smallThumbnail.setTransitionName("thumbnailTransition");
Pair<View, String> pair1 = Pair.create((View) holder.smallThumbnail, holder.smallThumbnail.getTransitionName());
ActivityOptionsCompat optionsCompat = ActivityOptionsCompat.makeSceneTransitionAnimation((Activity) mContext, pair1, pair2);
mContext.startActivity(intent, optionsCompat.toBundle());
在您的明细活动中
getWindow().setSharedElementEnterTransition(TransitionInflater.from(this).inflateTransition(R.transition.shared_element_transation));
mainImage.setTransitionName("thumbnailTransition");
此主图像是imageview,您想要转换以前的活动缩略图
shared_element_transation在res&gt;转换中创建一个xml
<?xml version="1.0" encoding="utf-8"?>
<transitionSet xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="500">
<changeBounds />
<fade />
</transitionSet>
答案 1 :(得分:0)
毕加索作品
<块引用>适配器
holder.smallImageView.setTransitionName("transition_name");
ActivityOptionsCompat optionsCompat = ActivityOptionsCompat.makeSceneTransitionAnimation(context, holder.smallImageView, "transition_name");
Intent intent = new Intent(context, DetailActivity.class);
context.startActivity(intent, optionsCompat.toBundle());
详细活动
Picasso.with(context)
.load(url)
.into(bigImageView, new Callback() {
@Override
public void onSuccess() {
bigImageView.setTransitionName("transition_name");
getWindow().setSharedElementEnterTransition(TransitionInflater.from(context).inflateTransition(R.transition.shared_element_transition));
}
@Override
public void onError() {
}
});
res/transition/shared_element_transition.xml
<?xml version="1.0" encoding="utf-8"?>
<transitionSet xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="500">
<changeBounds />
<fade />
</transitionSet>