Android:共享转换仅打开没有动画的活动

时间:2016-07-18 16:46:31

标签: android animation android-activity transition

我想为我的应用创建一个共享转换,但它不会像它应该的那样工作。它应该在下一个活动出现之前制作那个奇特的动画,但它只会打开它。而且图像也没有显示出来。我有这段代码:

 public void loadContent(final List<Post> posts){
    activity.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            ListAdapter adapter = new ListAdapter(posts, new View.OnClickListener(){
                @Override
                public void onClick(View v){
                    Intent intent = new Intent(MainActivity.this, PostViewActivity.class);

                    ImageView placeImage = (ImageView)v.findViewById(R.id.postPhoto);
                    TextView textView = (TextView)v.findViewById(R.id.textText);

                    Pair<View, String> imagePair = Pair.create((View) placeImage, getString(R.string.transition_image));
                    Pair<View, String> holderPair = Pair.create((View) textView, getString(R.string.transition_username));

                    ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(MainActivity.this, imagePair, holderPair);
                    //ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(MainActivity.this, holderPair);
                    ActivityCompat.startActivity(MainActivity.this, intent, options.toBundle());
                }
            });
            RecyclerView rv = (RecyclerView)findViewById(R.id.post_list);
            StaggeredGridLayoutManager lm = new StaggeredGridLayoutManager(1, StaggeredGridLayoutManager.VERTICAL);
            rv.setLayoutManager(lm);
            rv.setAdapter(adapter);

        }
    });

这两个XML文件: ID:方向= “垂直”                 &GT;

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="200dp"
                android:scaleType="centerCrop"
                android:paddingTop="0px"
                android:id="@+id/postPhoto"
                android:transitionName="@string/transition_image"/>
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textColor="@color/colorAccent"
                    android:id="@+id/usernameText"
                    android:transitionName="@string/transition_username"/>

另一个XML文件:

<ImageView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:transitionName="@string/transition_image"/>

<TextView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:transitionName="@string/transition_username"/>

它只打开新活动,但不打开图像和文本。我也尝试了它只与图像。怎么了?

0 个答案:

没有答案