0

私はthisガイドを使用して、複数の要素を持つアクティビティ共有要素遷移に単純なRecyclerViewを作成し、元の状態に戻しました。 。私は下のようにViewHolderを渡しますが、リターンアニメーションは実際には悪いRecyclerView上の別の要素に終わることがあります。正しい遷移または共用要素遷移なしでアクティビティに戻る

public void onPetClicked(PetRecyclerViewAdapter.PetViewHolder holder, int position) { 

      Intent newPostIntent = new Intent(getActivity(), PostDetailsActivity.class); 
      newPostIntent.putExtra("TYPE", mPostType); 
      newPostIntent.putExtra("POSTED_PET", mPetList.get(position)); 

      Pair<View, String> area = Pair.create(holder.itemView.findViewById(R.id.removable), "content_area"); 
      Pair<View, String> p1 = Pair.create(holder.itemView.findViewById(R.id.ivPetImage), "petImage"); 
      Pair<View, String> p2 = Pair.create(holder.itemView.findViewById(R.id.tvTitle), "postTitle"); 
      Pair<View, String> p3 = Pair.create(holder.itemView.findViewById(R.id.tvInfo), "postDescription"); 
      Pair<View, String> p4 = Pair.create(holder.itemView.findViewById(R.id.rlDate), "postDate"); 
      Pair<View, String> p5 = Pair.create(holder.itemView.findViewById(R.id.rlLocation), "postLocation"); 
      ActivityOptionsCompat options = ActivityOptionsCompat. 
        makeSceneTransitionAnimation(getActivity(), area, p1, p2, p3, p4,p5); 

      getActivity().startActivity(newPostIntent, options.toBundle()); 

私は

@Override 
    public void onBackPressed(){ 
     super.onBackPressed(); 
     finish(); 
     overridePendingTransition(android.R.anim.slide_in_left, android.R.anim.slide_out_right); 
    } 

@Override 
    public void onBackPressed(){ 
     super.onBackPressed(); 
     supportFinishAfterTransition(); 
    } 

を交換し、私の第二の活動におけるので、実際に戻り、アニメーションを使用しないことにしましたが、今私は戻ったときにこの問題を解決することができませんすべての共有要素は空です!

私は、戻り値の遷移が正しく機能するように、正しいアイテムをフェードインさせるためのフェーディングエフェクトを意味するか、リターントランジションを一括して取り除くかを考えようとしています。

編集:実際に動作させる方向で、ViewHolderではなくクリックされたビューを取得して使用しようとしましたが、同じ結果が得られました。リサイクラビューをスクロールしてアイテムを開くとすぐに、ビューは開始したビューとは異なる行にアニメーション表示されます。

public void onPetClicked(View view, PetRecyclerViewAdapter.PetViewHolder holder, int position) { 
      mPetList.get(position); 

      Intent newPostIntent = new Intent(getActivity(), PostDetailsActivity.class); 
      newPostIntent.putExtra("TYPE", mPostType); 
      newPostIntent.putExtra("POSTED_PET", mPetList.get(position)); 

      Pair<View, String> area = Pair.create(view.findViewById(R.id.removable), "content_area"); 
      Pair<View, String> p1 = Pair.create(view.findViewById(R.id.ivPetImage), "petImage"); 
      Pair<View, String> p2 = Pair.create(view.findViewById(R.id.tvTitle), "postTitle"); 
      Pair<View, String> p3 = Pair.create(view.findViewById(R.id.tvInfo), "postDescription"); 
      Pair<View, String> p4 = Pair.create(view.findViewById(R.id.rlDate), "postDate"); 
      Pair<View, String> p5 = Pair.create(view.findViewById(R.id.rlLocation), "postLocation"); 
      ActivityOptionsCompat options = ActivityOptionsCompat. 
        makeSceneTransitionAnimation(getActivity(), area, p1, p2, p3, p4,p5); 

      getActivity().startActivity(newPostIntent, options.toBundle()); 
     } 
    }); 

答えて

2

super.onBackPressed()なしfinish()を呼び出してみてください。

あなたのアクティビティはAppCompatActivityだと思いますか?終了する前に保留中の遷移を実行します。

+0

よろしくお願いします。ありがとう – eiran

関連する問題