带有共享元素的Android片段转换

带有共享元素的Android片段转换,android,android-fragments,transitions,shared-element-transition,Android,Android Fragments,Transitions,Shared Element Transition,各位!! 我有两个碎片。在一个片段中,我在卡片上有一个小图像。在2d片段中,我在布局的标题中有相同的图像。我想将这个图像的共享元素从一个片段转换到另一个片段,就像这个例子中一样 2d片段: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/main" android:layout_width="match_parent" android:layout_heigh

各位!! 我有两个碎片。在一个片段中,我在卡片上有一个小图像。在2d片段中,我在布局的标题中有相同的图像。我想将这个图像的共享元素从一个片段转换到另一个片段,就像这个例子中一样

2d片段:

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#f2f4f7">
<CustomScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/scroll_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="#f2f4f7">
    <LinearLayout
        android:id="@+id/content_wrapper"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:divider="@drawable/vertical_divider"
        android:showDividers="middle">
        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <RelativeLayout
                android:id="@+id/header_wrapper"
                android:layout_width="match_parent"
                android:layout_height="166.7dp">
                <ImageView
                    android:id="@+id/share_image"
                    android:transitionName="imageTransition"
                    android:layout_width="match_parent"
                    android:layout_height="166.7dp"
                    android:src="@drawable/friday"/>
transition_move.xml

<transitionSet xmlns:android="http://schemas.android.com/apk/res/android">
   <changeImageTransform />
   <changeBounds/>
</transitionSet>

但是没有图像动画发生。它出现在左上角,并调整大小

查看答案

因为我在两个片段之间共享的视图是另一个片段的子视图 视图(RelativeLayout)在第二个片段中,您需要添加 将转换转换为您的转换


基本上,您需要的是在您的transition\u move.xml

中添加一个
,动画非常有趣。我想说,如果你使用一个片段列表,当你点击一个片段时,它就会启动,动画就会占据整个屏幕。所有额外的视图都已经在片段中了,但是它们被隐藏起来了,以进行某种形式的标志更改
<transitionSet xmlns:android="http://schemas.android.com/apk/res/android">
   <changeImageTransform />
   <changeBounds/>
</transitionSet>
<transitionSet xmlns:android="http://schemas.android.com/apk/res/android">
   <changeImageTransform />
   <changeBounds/>
</transitionSet>