我一直在使用 ActivityOptionsCompat.makeSceneTransitionAnimation()
在我的应用程序中使用共享元素转换和 ActivityCompat.startActivityForResult()
使用以下一些 XML 代码:
...
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:transitionName="@string/transition_1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="16sp"
android:paddingBottom="16sp">
...
</android.support.v7.widget.CardView>
...
这里的一切都很好。
但是,由于我正在使用 CardView
中的内容多次,我决定将其移动到新布局并使用 <include>
引用它。
这是新的布局文件:
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
...
</android.support.v7.widget.CardView>
和旧文件:
...
<include layout="@layout/my_card_content"
android:transitionName="@string/transition_1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="16sp"
android:paddingBottom="16sp" />
...
现在,出于某种原因,共享元素转换似乎不起作用。
我该如何解决这个问题?
最佳答案
原来问题是因为我需要包含android:transitionName
在我的卡片布局中,这样我的卡片布局看起来像这样:
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:transitionName="@string/transition_1"
android:layout_width="match_parent"
android:layout_height="wrap_content">
...
</android.support.v7.widget.CardView>
意思是我的<include>
不需要它标签:
<include layout="@layout/my_card_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="16sp"
android:paddingBottom="16sp" />
关于Android 共享元素转换不适用于 <include> 标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39712836/