0

私はrecyclerview項目のクリックで共有要素の遷移を使用しています。アイテムをクリックすると、imageViewは詳細アクティビティにスムーズに移行します。ただし、戻るボタンをクリックすると、imageViewの遷移は常にrecyclerViewの最後の項目に移動します。 私はそれの背後にある理由を理解することができません、任意の入力が感謝しています。グリッド上での共有要素の遷移のリバースアニメーションRecyclerviewは常に最後の項目に移動します

ここに私のコードです。

<!-- Base application theme. --> <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> 
    <!-- Customize your theme here. --> 
    <item name="colorPrimary">@color/colorPrimary</item> 
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
    <item name="colorAccent">@color/colorAccent</item> 
    <item name="android:windowContentTransitions">true</item> </style> 
gridItem.xml

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:foreground="?attr/selectableItemBackground"> 

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/recyclerItem" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:padding="@dimen/spacing_xsmall"> 

     <android.support.v7.widget.AppCompatImageView 
      android:id="@+id/categoryImage" 
      android:layout_width="120dp" 
      android:layout_height="120dp" 
      android:layout_gravity="center" 
      android:background="@color/colorPrimary" 
      android:scaleType="fitXY" 
      android:transitionName="AnimateTitle" 
      /> 

     <TextView 
      android:id="@+id/title" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:background="@color/colorPrimary" 
      android:gravity="center" 
      android:padding="@dimen/spacing_large" 
      android:textColor="@color/colorAccent" 
      android:textStyle="bold"/> 
    </LinearLayout> 
</FrameLayout> 

DetailActivity.xml

<?xml version="1.0" encoding="utf-8"?> 
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.thinkinghats.isittrue.GameActivity" 
    > 

    <android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:layout_height="56dp" 
     android:layout_width="0dp" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintHorizontal_bias="0.0" 
     app:layout_constraintTop_toTopOf="parent" 
     android:layout_marginTop="8dp"> 

     <android.support.v7.widget.AppCompatImageView 
      android:id="@+id/categoryImage" 
      android:layout_width="56dp" 
      android:layout_height="56dp" 
      android:scaleType="fitXY" 
      android:transitionName="AnimateTitle" 
      /> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:id="@+id/title" 
      android:textSize="25sp" 
      android:textStyle="bold" 
      android:textColor="@color/colorAccent" 
      /> 
    </android.support.v7.widget.Toolbar> 

    <android.support.v7.widget.CardView 
     xmlns:card_view="http://schemas.android.com/tools" 
     android:id="@+id/card_question" 
     android:layout_width="0dp" 
     android:layout_height="300dp" 
     android:layout_below="@id/toolbar" 
     android:layout_margin="@dimen/spacing_xlarge" 
     android:background="@color/white" 
     android:clickable="true" 
     android:foreground="?attr/selectableItemBackground" 
     app:layout_constraintBottom_toBottomOf="parent" 
     app:layout_constraintHorizontal_bias="0.0" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintTop_toBottomOf="@+id/toolbar" 
     app:layout_constraintVertical_bias="0.502" 
     card_view:cardCornerRadius="4dp"> 
    </android.support.v7.widget.CardView> 
</android.support.constraint.ConstraintLayout> 

そして、これは私が

public void onItemClick(View view, ViewModel viewModel) { 
     Intent startIntent = new Intent(this, DetailActivity.class); 
     Bundle bundle = new Bundle(); 
     bundle.putString("categoryTitle", viewModel.getText()); 
     bundle.putInt("categoryImage", viewModel.getImage()); 
     startIntent.putExtras(bundle);   
     startActivity(startIntent,ActivityOptions.makeSceneTransitionAnimation(this,view.findViewById(R.id.categoryImage),"AnimateTitle").toBundle());  
    } 
MainActivity

からの移行を呼び出す方法です

答えて

0

何かを試している間、私は、recyclerView onEnterAnimationComplete()のためのアダプタをセットアップしました。 onCreate()イベントでアダプタを設定すると、問題は解決されます。

私は、アダプタがonEnterAnimationComplete()をリセットするために使用されていたので、どのアイテムが起動したかを知るための移行方法がないと推測しています。

関連する問題