0

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 I'm 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"/>
</RelativeLayout>

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"/>
</RelativeLayout>

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>
RamenChef
  • 5,557
  • 11
  • 31
  • 43
  • I would suggest you to take a look at this github repository. Its really nice and will help you a lot.https://github.com/lgvalle/Material-Animations – Raghunandan Oct 26 '16 at 17:32

1 Answers1

3

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"/>
Efe Budak
  • 659
  • 5
  • 27
  • Great, that totally worked! However, what if I'm setting the first image view with a library such as glide or picasso. In those cases my source isn't set in the xml? – Ryan Cirese Oct 26 '16 at 17:42
  • Then you need to set your image view again on the second activity too. You can pass the related bitmap as a byte array. [here is the link for it] (http://stackoverflow.com/questions/11010386/send-bitmap-using-intent-android) Can you also check the answer if that works for you. :) – Efe Budak Oct 26 '16 at 17:44