共享元素转换和GridView

时间:2015-05-13 12:55:16

标签: android android-intent android-animation android-transitions

我似乎无法从主活动中的图像和详细活动中的图像创建共享元素转换。

问题似乎出现在.makeSceneTransitionAnimation个论点上。我已经传递了对活动的引用,图像和共享转换名称文本,这些文本在两个活动资源中都有标记。 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());
            }
        });

1 个答案:

答案 0 :(得分:0)

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