Android 共享元素转换不适用于 <include> 标记

标签 android android-layout shared-element-transition

我一直在使用 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/

相关文章:

android - 退出过渡不适用于 fragment 中 ViewPager 中的 ImageView 共享元素

java - 使用 DOM Android 从 Xml 读取 UTF8 和 Cp1256

java - Android 中使用的 PreferenceManager 和 SharedPreference 类是什么?

android - 在 Android Studio 中运行重建项目后会发生什么?

android - 放大移动网站和网页 View

android - 具有半径的 CardView 上的共享元素转换

android - SharedElementTransition无法使用Glide正确缩放图像比例

安卓指纹扫描仪应用程序

java - 使用支持包中的 fragment 创建选项卡栏

android如何使用layout_height ="match_parent"将Imagebutton放在右边