片段共享元素转换的片段不会为

时间:2017-12-15 22:01:21

标签: listview transition shared-element-transition

以下是app(ListView)https://git.nwt.fhstp.ac.at/dm171521/app-shared-element-transiton

的回购

与RecyclerView完全相同(我希望它会有所帮助) https://git.nwt.fhstp.ac.at/dm171521/app-shared-element-transiton/commits/recyclerView-shared-element

没有太复杂(只有重要的一点):

  1. 创建活动 - >将片段加载到viewPager
  2. 将项目从JSON加载到listView
  3. ProductsFragment
  4. 项目点击 - >创建第二个片段
  5. 添加具有唯一transitionName
  6. 的共享元素(TextView) 当前片段中的
  7. setSharedElementEnterTransition
  8. 的BeginTransaction(...)
  9. 在新片段中获取唯一的transitionName,并将其设置为该片段中的等效TextView转换名称。
  10. 新片段中的
  11. setSharedElementEnterTransition
  12. 什么都没有,新创建的片段就出现了。第一个片段中的textView没有动画,第二个中的textView的值没有变化。
  13. transitionNames分别以编程方式设置在每个Fragment中,并且在两种布局中都是唯一的。

    如果你问我“你试过写这个而不是那个”我可能会回答是,因为我试图从一百万个教程和git存储库中复制没有成功,回购的当前状态并不代表我尝试过的所有百万种组合。所以我非常绝望!

    甚至写一些简单的东西,如“使用片段1和TextView创建活动 - >单击TextView - >创建片段2并添加sharedElement(TextView) - >打开”也没有做任何事情。我不知道我做错了什么。

    从git repo复制整个应用程序虽然有效但是在我的情况下尝试实现不起作用。

    此外,还启用了以下功能

    windowContentTransitions
    

    片段1

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    
        // We want to animate the title to the new fragment => shared element
        final TextView title = (TextView) view.findViewById(R.id.product_name_list);
        Fragment detailsFragment = ProductDetails_fragment.newInstance();
    
        Bundle bundle = new Bundle();
        bundle.putString("TRANSITION_NAME", title.getTransitionName());
        detailsFragment.setArguments(bundle);
    
        Log.i("BEFORE", title.getTransitionName());
    
        // or getActivity().getSuppportFragmentManager()
        FragmentTransaction trans = getFragmentManager().beginTransaction();
        trans.replace(R.id.products_layout, detailsFragment)
                .addToBackStack(null)
                .addSharedElement(title, title.getTransitionName())
                .commit();
    }
    

    片段2

     @Override
        public void onCreate(@Nullable Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
    
            Transition move = TransitionInflater.from(getContext()).inflateTransition(android.R.transition.move);
            setEnterTransition(move);
            setSharedElementReturnTransition(move);
            setSharedElementEnterTransition(move);
        }
    
        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
            View rootView = inflater.inflate(R.layout.product_details_layout, container, false);
            TextView detailsTitle = (TextView)rootView.findViewById(R.id.detail_title);
    
            Bundle bundle = getArguments();
            String transitionName = bundle.getString("TRANSITION_NAME");
    
            detailsTitle.setTransitionName(transitionName);
            Log.i("AFTER", detailsTitle.getTransitionName());
    
            return rootView;
        }
    

    如果有人有几分钟时间克隆这个回购并看看发生了什么,我将非常感激。

0 个答案:

没有答案