共享元素过渡和 GridView

Shared Elements Transition and GridViews

我似乎无法从主要 activity 中的图像和细节 activity 中的图像创建共享元素过渡。

问题似乎出在 .makeSceneTransitionAnimation 参数上。我已经传递了对 activity 的引用、图像和在两个 activity 资源中标记的共享转换名称文本。 Android Studio 说这是一个错误,它看起来好像与 GridView 有关 任何人都可以看到问题是什么吗?

如果您需要任何其他代码示例,请告诉我?

CustomGrid adapter = new CustomGrid(ActorList.this, actorsNames, actorsImages);
        actorGrid = (GridView) findViewById(R.id.grid);
        actorGrid.setAdapter(adapter);

        final ImageView sharedImage = (ImageView) findViewById(R.id.grid_actor_image);

        actorGrid.setOnItemClickListener(new AdapterView.OnItemClickListener() {


            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                                    int position, long id) {

                Intent detailIntent = new Intent(getApplicationContext(), Detail.class);

                ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(this, sharedImage, "profile");

                detailIntent.putExtra("name", actorObjectArrayList.get(position).getName());
                detailIntent.putExtra("description", actorObjectArrayList.get(position).getDescription());
                detailIntent.putExtra("dob", actorObjectArrayList.get(position).getDob());
                detailIntent.putExtra("country", actorObjectArrayList.get(position).getCountry());
                detailIntent.putExtra("spouse", actorObjectArrayList.get(position).getHeight());
                detailIntent.putExtra("children", actorObjectArrayList.get(position).getChildren());
                detailIntent.putExtra("image", actorObjectArrayList.get(position).getImage());
                startActivity(detailIntent, options.toBundle());
            }
        });

您正在传递 this,它是对当前对象的引用,即 OnItemClickListener。因为你在一个内部 class 中,所以你实际需要传递的是 YourActivityName.thisActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(YourActivityName.this, sharedImage, "profile");