title: Glitchy shared element transition between recyclerview and viewpager
body: <p>Hi i have made an app where i'm using shared element transition for some animation between recyclerview which is in fragment and a slider viewpager which is in activity.
  Now the problem is that when i apply shared element transition and click recyclerview  it blinks for a moment and the detail activity starts but without animation and when i press back button shared element animation occurs but that too very glitchy.
  By glitchy i mean when i press back cardview's white background pops and then image comes over it.
  For that i saw some tutorials on youtube as well as searched on google and found some related <a href="https://stackoverflow.com/questions/41708595/shared-element-transition-not-working?utm_medium=organic&amp;utm_source=google_rich_qa&amp;utm_campaign=google_rich_qa">So question</a> but still not able to figure out where i am going wrong with this because i have given same transition name to both the imageviews.
  so please if someone can assist me here.
  Thank you</p>
  
  <p>Here is my code for recyclerview and styles.xml</p>
  
  <p><strong>styles.xml</strong></p>
  
  <pre><code>&lt;resources xmlns:tools="http://schemas.android.com/tools"&gt;
  
      &lt;!-- Base application theme. --&gt;
      &lt;style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"&gt;
          &lt;!-- Customize your theme here. --&gt;
          &lt;item name="colorPrimary"&gt;@color/colorPrimary&lt;/item&gt;
          &lt;item name="colorPrimaryDark"&gt;@color/colorPrimaryDark&lt;/item&gt;
          &lt;item name="colorAccent"&gt;@color/colorAccent&lt;/item&gt;
          &lt;item name="android:windowContentTransitions" tools:targetApi="lollipop"&gt;true&lt;/item&gt;
          &lt;item name="android:windowAllowEnterTransitionOverlap" tools:targetApi="lollipop"&gt;true&lt;/item&gt;
          &lt;item name="android:windowAllowReturnTransitionOverlap" tools:targetApi="lollipop"&gt;true&lt;/item&gt;
          &lt;item name="android:windowSharedElementEnterTransition" tools:targetApi="lollipop"&gt;@android:transition/move&lt;/item&gt;
          &lt;item name="android:windowSharedElementExitTransition" tools:targetApi="lollipop"&gt;@android:transition/move&lt;/item&gt;
      &lt;/style&gt;
  
  &lt;/resources&gt;
  </code></pre>
  
  <p><strong>ViewHolder</strong></p>
  
  <pre><code> public class VH extends RecyclerView.ViewHolder implements View.OnClickListener{
          ImageView iv;
          TextView tv;
          HWRatioContainer ivc;
          Context context;
          int[] images;
  
          private AtomicBoolean enterTransitionStarted;
          public static final String EXTRA_TRANSITION_IMAGE = "image";
  
          CustomButton top_recycler_button;
          public VH(View itemView,Context context,int[] images) {
              super(itemView);
              iv = (ImageView) itemView.findViewById(R.id.iv);
              this.context = context;
              this.images = images;
  
              this.enterTransitionStarted = new AtomicBoolean();
              top_recycler_button = (CustomButton)itemView.findViewById(R.id.top_recycler_button);
              itemView.setOnClickListener(this);
              //tv = (TextView) itemView.findViewById(R.id.tv);
              ///ivc = (HWRatioContainer) itemView.findViewById(R.id.ivc);
             /*ivc.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                  @Override
                  public void onGlobalLayout() {
                      if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.JELLY_BEAN) {
                          ivc.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                      } else {
                          ivc.getViewTreeObserver().removeGlobalOnLayoutListener(this);
                      }
                      ivc.setTranslationX(ivc.getWidth() &gt;&gt; 4);
                  }
              });*/
  
          }
  
          @SuppressLint("RestrictedApi")
          @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
          @Override
          public void onClick(View view) {
              Intent intent = new Intent(context,DetailsActivity.class);
              intent.putExtra("slider_image",images[getAdapterPosition()]);
              iv.setTransitionName(context.getString(R.string.first_page_transition));
              ActivityOptionsCompat compat = ActivityOptionsCompat.makeSceneTransitionAnimation((MainActivity)context,iv,ViewCompat.getTransitionName(iv));
              context.startActivity(intent,compat.toBundle());
          }
      }
  </code></pre>
  
  <p>and code for adapter of viewpager which is in activity</p>
  
  <pre><code>@TargetApi(Build.VERSION_CODES.LOLLIPOP)
      @RequiresApi(api = Build.VERSION_CODES.KITKAT)
      @NonNull
      @Override
      public Object instantiateItem(@NonNull ViewGroup container, int position) {
          layoutInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          View view = layoutInflater.inflate(R.layout.custom_dots_layout,null);
          imageView = (ImageView)view.findViewById(R.id.detail_viewpager_image);
          //Intent intent  = new Intent();
          imageView.setImageResource(getImage());
  
          if(Build.VERSION.SDK_INT&gt;Build.VERSION_CODES.LOLLIPOP){
              imageView.setTransitionName(context.getString(R.string.first_page_transition));
  
          }
          ViewPager viewPager1 = (ViewPager)container;
          viewPager1.addView(view,0);
          return view;
      }
  </code></pre>