android - SharedElements 过渡在 Go 上有效,但在 Back 上无效
问题描述
我正在学习如何将 sharedelements 动画与导航组件一起使用。
当我调用 new fragment 时,这件事起作用,为对象设置动画,但当我推回时不起作用。
我在回收站视图中的代码
CardView cardviewBackgroundImage = view.findViewById(R.id.card_main_image);
TextView storeName = view.findViewById(R.id.store_name);
Map<View, String> transitionObjects = new HashMap<View, String>();
transitionObjects.put(cardviewBackgroundImage, cardviewBackgroundImage.getTransitionName());
transitionObjects.put(storeName, storeName.getTransitionName());
FragmentNavigator.Extras extras = new FragmentNavigator.Extras.Builder()
.addSharedElements(transitionObjects)
.build();
Bundle bundle = new Bundle();
bundle.putString("subfix", subfix);
bundle.putString("key", key);
Navigation.findNavController(getView()).navigate(R.id.action_mainScreenFragment_to_placeViewFragment, bundle, null, extras);
在目标片段中,我的代码是:
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
postponeEnterTransition();
sharedElementEnterTransition = TransitionInflater.from(getContext()).inflateTransition(android.R.transition.move);
this.setSharedElementEnterTransition(sharedElementEnterTransition);
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
String subfix = getArguments().getString("subfix");
String key = getArguments().getString("key");
CardView cardviewBackgroundImage = view.findViewById(R.id.card_main_image);
TextView storeName = view.findViewById(R.id.store_name);
cardviewBackgroundImage.setTransitionName("cardimage" + subfix + key);
storeName.setTransitionName("storename" + subfix + key);
startPostponedEnterTransition();
}
提前致谢!
解决方案
推荐阅读
- python - 单独访问 numpy 数组中的元素
- python - 使用熊猫数据向散景图添加简单的下拉列表
- android - FAILURE:构建失败并出现异常 - Flutter
- javascript - 无法按 [] 拆分并替换数组中的字符串
- python - 向 Datatable 添加行无法按预期工作
- python - 基本的石头、纸、剪刀对我的计算器不起作用
- c - 使用 scanf 扫描 %d 格式说明符中的八进制和十六进制数
- javascript - React 不渲染 Axios 调用的 map 函数
- module - 我怎样才能拥有一个“私有”的 Erlang 模块?
- javascript - Nuxt.js auth 模块不重定向登录用户