共享元素过渡到RecycleView不起作用

时间:2018-08-09 08:52:28

标签: android android-recyclerview shared-element-transition

我在父活动中有一组图像(水平线性布局),我想将所有元素过渡到RecycleView活动(网格布局) 当我启动RecycleView活动时,共享元素过渡不起作用,但是在返回父活动时它起作用。

ParentActivity点击方法:

Intent intent = new Intent(this, ChildActivity.class);
Pair[] pairs = new Pair[mContent.getChildCount()];
for(int i = 0; i < mContent.getChildCount(); i++){
    View view = mContent.getChildAt(i);
    view.setTransitionName("trans"+i);
    Pair<View, String> pair = Pair.create(view, view.getTransitionName());
    pairs[i] = pair;
}
ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(this, pairs);
ActivityCompat.startActivity(this, intent, options.toBundle());

RecycleViewAdapter代码:

 @Override
public void onBindViewHolder(final ItemViewHolder holder, int position) {
    ViewCompat.setTransitionName(holder.imageView, "trans"+position);
}

0 个答案:

没有答案