I put together a simple sample app to try shared elements transition with nested views (source code on github). In this case it's an ImageView inside a CardView. I got the following results:
As you can see, while the parent view (CardView) animates nicely the child view (ImageView) doesn't. It looks like it animates from the upper left corner of the future position of the CardView.
The Adapter
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
final View v = mInflater.inflate(R.layout.grid_item, null);
v.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(new Intent(mContext, DialogActivity.class));
ActivityOptions options = ActivityOptions
.makeSceneTransitionAnimation((Activity) mContext,
Pair.create(v, "background_transition"),
Pair.create(v.findViewById(R.id.image), "image_transition"));
mContext.startActivity(i, options.toBundle());
}
});
return v;
}
The original layout
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="1.5dp"
android:transitionName="background_transition"
card_view:cardBackgroundColor="@android:color/holo_red_dark">
<com.tlongdev.sharedelementstest.SquareImageLayout
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:transitionName="image_transition"
android:src="@android:drawable/btn_star_big_on"/>
</android.support.v7.widget.CardView>
The target layout
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
tools:context="com.tlongdev.sharedelementstest.DialogActivity">
<android.support.v7.widget.CardView
android:id="@+id/card"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
card_view:cardBackgroundColor="@android:color/holo_red_dark"
card_view:cardCornerRadius="4dp"
card_view:cardElevation="10dp"
android:transitionName="background_transition">
<com.tlongdev.sharedelementstest.SquareImageLayout
android:layout_margin="25dp"
android:layout_width="100dp"
android:layout_height="100dp"
android:src="@android:drawable/btn_star_big_on"
android:transitionName="image_transition" />
</android.support.v7.widget.CardView>
</RelativeLayout>
Any help would be appreciated.
UPDATE 16/11/15: It looks like this issue has been solved on Marshmallow, but still present on Lollipop (on a emulator at least).