Ryan Cirese Ryan Cirese - 1 year ago 61
Android Question

Shared element transitions not working, blank screen

My transitions aren't working, the first image view shows the drawable but upon running animation it just ends with a white screen. Not sure what Im missing.

Main Layout

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<ImageView
android:id="@+id/main_image"
android:transitionName="@string/transition_string"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_width="100dp"
android:layout_height="100dp"
android:src="@drawable/image"/>




Second Activity Layout

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<ImageView
android:id="@+id/second_image"
android:transitionName="@string/transition_string"
android:layout_width="match_parent"
android:layout_height="300dp"/>




Main Activity

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

findViewById(R.id.main_image).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
animate();
}
});
}

public void animate(){
Intent intent = new Intent(this, SecondActivity.class);
String transitionName = getString(R.string.transition_string);
View viewStart = findViewById(R.id.main_image);
ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(this, viewStart, transitionName);
ActivityCompat.startActivity(this, intent, options.toBundle());
}


}

Second Activity

public class SecondActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
}


}

Style

<!-- 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>

Answer Source

Add src to second_image, such as;

<ImageView
android:id="@+id/second_image"
android:transitionName="@string/transition_string"
android:layout_width="match_parent"
android:layout_height="300dp"
android:src="@drawable/image"/>