android - Reverse animation for Shared Element transition on Grid Recyclerview always moves to last item -


i using shared element transition on click of recyclerview item. on click of item imageview smoothly transitions detail activity. however, on clicking button, transition imageview goes last item of recyclerview. not able understand reason behind it, inputs appreciated.

here code.

<!-- base application theme. --> <style name="apptheme" parent="theme.appcompat.light.noactionbar">     <!-- customize 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> 

and how call transition mainactivity

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());          } 

as turns out had setup adapter recyclerview onenteranimationcomplete() while trying something. after setting adapter on oncreate() event issue solved.

i guessing since adapter used reset onenteranimationcomplete(), there no way transition know item had started it.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -