如何在 activity 转换中包含一个未附加的视图?

How to include an unattached View in the activity transition?

我绘制了一个未附加到任何父视图的视图。

这是对 RecyclerView 的装饰。视图固定在底部并在其对应部分出现在列表中时消失。

一切正常,但是:

When i leave the activity the View doesn't fade with the rest of the views in the activity's transition.

It stays until the end of the animation and then disappears immediately.

( see large green view in the demo )

如何在 activity 的退出过渡中包含此独立视图?


我创建了一个最小的 Android Studio 项目来重现这个问题: https://github.com/Ostkontentitan/transition-issue-demo

(为了更好地查看问题,可以将您的手机动画比例设置为 >= 5)


这是一个演示:

Not-too-educated猜测

(因为没试过,几个月没用过Transition Framework)

TF(过渡框架)的工作方式是计算过渡的 start/end 值并执行实现此目的所需的动画。

RecyclerView 装饰不是 "views" 布局的一部分,因此 TF 不知道它的存在。它当然知道你的 RecyclerView,因为它包含在动画的 ViewGroup 中。

您可能已经知道这一点,但无论如何,我想我在这里尝试做的是创建一个自定义过渡框架过渡(它们并不难做,您甚至可以查看 TransitionEverywhere 并查看该库如何在框架中实现一些缺失的转换);然后,在您的 CustomTransition 中,您可以尝试插入动画值,以便回收器视图可以随着动画的进行而重新装饰(就像动画的 alpha 值一样,您的自定义装饰器将 "paint" 使用所述 alpha)。

现在......事实上,我不得不做一次类似的事情,其中​​自定义转换是 "driving" 一些外部视图(当时原因) :) 但是...它 不是 RecyclerView 项目装饰,我的只是 "views",所以我不确定你是否可以这样做 w/a装修。

我觉得值得一试。

transitionName 添加到 RecyclerView 的 xml 布局。

您看到的过渡动画是因为 ActivityOptions.makeSceneTransitionAnimation(this@ItemListActivity),如果您将 transitionName 添加到视图中,效果很好。