1

画像は最初にその場所、つまり詳細アクティビティの画像ビューに完全に移動し、メインのアクティビティにも完全に戻りますが、次に同じ画像をクリックすると、遷移アニメーションが画像を詳細の不適切な (高すぎる) オフセットに移動しますアニメーションが完了すると、画像は正しい位置に「ワープ」するように見えます。

ここに私の DetailActivity.java ファイルがあります:

package com.akshitjain.popularmovies;

import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.ViewTreeObserver;
import android.widget.ImageView;
import android.widget.TextView;


import com.squareup.picasso.Callback;
import com.squareup.picasso.Picasso;

public class DetailActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_detail);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        postponeEnterTransition();
    }

    ImageView backdropImageView = (ImageView)       findViewById(R.id.detail_image_view);
    final ImageView posterImageView = (ImageView) findViewById(R.id.detail_poster);
    TextView overviewTextView = (TextView) findViewById(R.id.overview_text_view);
    TextView releaseDateTextView = (TextView) findViewById(R.id.release_date);
    TextView userRatingTextView = (TextView) findViewById(R.id.user_rating);
    TextView genreTextView = (TextView) findViewById(R.id.genre);
    genreTextView.setText("");
    Genre genreObject = new Genre();
    String genreName;

    Intent intent = getIntent();

    if (intent != null && intent.hasExtra(Constants.MOVIE_OBJECT_PARCELABLE_EXTRA)) {
        Movies movies = intent.getParcelableExtra(Constants.MOVIE_OBJECT_PARCELABLE_EXTRA);
        int[] genre;
        genre = movies.genre;
        for (int i = 0; i < genre.length; ++i) {
            genreName = genreObject.getGenreName(genre[i]);
            genreTextView.append(genreName);
            if (i < genre.length - 1) {
                genreTextView.append(", ");
            }
        }

        setTitle(movies.originalTitle);
        Picasso.with(getApplicationContext())
                .load((Constants.IMAGE_BASE_URL + Constants.POSTER_SIZE_LARGE).trim() + movies.backdropPath)
                .into(backdropImageView);
        Picasso.with(getApplicationContext())
                .load((Constants.IMAGE_BASE_URL + Constants.POSTER_SIZE_SMALL).trim() + movies.posterPath)
                .into(posterImageView, new Callback() {
                            @Override
                            public void onSuccess() {
                                posterImageView.getViewTreeObserver().addOnPreDrawListener(
                                        new ViewTreeObserver.OnPreDrawListener() {
                                            @Override
                                            public boolean onPreDraw() {
                                                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                                                    posterImageView.getViewTreeObserver().removeOnPreDrawListener(this);
                                                    startPostponedEnterTransition();
                                                }
                                                return true;
                                            }
                                        }

                                );
                            }

                            @Override
                            public void onError() {
                            }
                        }

                );
        overviewTextView.setText(movies.overview);
        releaseDateTextView.setText(movies.releaseDate);
        userRatingTextView.setText(movies.userRating);
    }

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_detail, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    switch (id) {
        case android.R.id.home:
            supportFinishAfterTransition();
            return true;
        case R.id.action_settings:
            return true;
    }
    return super.onOptionsItemSelected(item);
}
}
4

1 に答える 1