简体   繁体   English

如何将不参与从片段 A 的共享元素转换的视图添加到片段 B?

[英]How to add views to Fragment B that are not involved in a shared element transition from Fragment A?

So I have a recycler view item that looks like this: Transition View Start所以我有一个看起来像这样的回收器视图项目:过渡视图开始

And I want to end up with this: Transition View End我想以这个结束Transition View End

The problem I keep getting is an index out-of-bounds exception.我不断遇到的问题是索引越界异常。 So the start has 6 views that transition and all have the appropriate transition name based on a unique id.所以开始有 6 个过渡视图,并且所有视图都具有基于唯一 ID 的适当过渡名称。 The end view has all 6 but 2 more, the small water and thermometer images.最终视图有 6 个,但还有 2 个,小水和温度计图像。 Those two have no transition names.这两个没有过渡名称。 Yet they keep getting added to a list that stores the transition views.然而,它们不断被添加到存储过渡视图的列表中。 The following code is in DefaultSpecialEffectsController.java - line 701以下代码在 DefaultSpecialEffectsController.java - 第 701 行

void captureTransitioningViews(ArrayList<View> transitioningViews, View view) {
    if (view instanceof ViewGroup) {
        if (!transitioningViews.contains(view)
                && ViewCompat.getTransitionName(view) != null) {
            transitioningViews.add(view);
        }
        ViewGroup viewGroup = (ViewGroup) view;
        int count = viewGroup.getChildCount();
        for (int i = 0; i < count; i++) {
            View child = viewGroup.getChildAt(i);
            if (child.getVisibility() == View.VISIBLE) {
                captureTransitioningViews(transitioningViews, child);
            }
        }
    } else {
        if (!transitioningViews.contains(view)) {
            transitioningViews.add(view);
        }
    }
}

And the index out of bounds occurs here FragmentTranstionImpl.java - line 176并且索引越界发生在这里 FragmentTranstionImpl.java - 第 176 行

void setNameOverridesReordered(final View sceneRoot,
        final ArrayList<View> sharedElementsOut, final ArrayList<View> sharedElementsIn,
        final ArrayList<String> inNames, final Map<String, String> nameOverrides) {
    final int numSharedElements = sharedElementsIn.size();
    final ArrayList<String> outNames = new ArrayList<>();

    for (int i = 0; i < numSharedElements; i++) {
        final View view = sharedElementsOut.get(i);
        final String name = ViewCompat.getTransitionName(view);
        outNames.add(name);
        if (name == null) {
            continue;
        }
        ViewCompat.setTransitionName(view, null);
        final String inName = nameOverrides.get(name);
        for (int j = 0; j < numSharedElements; j++) {
            if (inName.equals(inNames.get(j))) {
                ViewCompat.setTransitionName(sharedElementsIn.get(j), name);
                break;
            }
        }
    }

Is it possible to add the two small icons and in general any view, without them being in the starting transition view in recycler view in Fragment A?是否可以添加两个小图标和一般的任何视图,而它们不在 Fragment A 的回收器视图中的起始过渡视图中?

This is a bug in Fragments , specifically fixed in Fragment 1.3.5 .这是 Fragment 中的一个错误,专门在Fragment 1.3.5 中修复。 You'll need to upgrade to that version.您需要升级到该版本。

implementation "androidx.fragment:fragment:1.3.5"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何共享元素从片段到活动的转换 - how to Shared element transition from a fragment to an activity 片段共享元素转换使用 add() 而不是 replace()? - Fragment shared element transition with add() instead of replace()? 共享元素从活动过渡到片段的示例 - example for shared element transition from activity to fragment 如何在使用导航组件和 safeArgs 从回收器视图导航到片段时添加共享元素转换? - How to add shared element transition when navigating from recycler view to a fragment while using navigation components and safeArgs? 如何在对话框片段中使用共享元素过渡 - how to use shared element transition in a dialog fragment 共享元素在新活动上从片段到片段的转换 - Shared Element Transition from fragment to fragment on new activity 共享元素片段过渡不起作用 - Shared element fragment transition not working 具有片段共享元素过渡的WindowInset - WindowInset with Fragment Shared Element Transition 使用共享元素的Android片段转换 - Android fragment transition with shared element 如何使用从 RecyclerView 到 Fragment 的共享转换 - How to used a shared transition from RecyclerView to a Fragment
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM