【问题标题】:Activity is not visible when using shared element transition使用共享元素转换时活动不可见
【发布时间】:2019-10-23 12:08:36
【问题描述】:

我正在尝试使用共享元素转换从列表活动转移到详细信息活动 但是当使用共享元素时,目标活动是不可见的

当我不使用共享元素时它正常工作

但是当我使用共享元素转换活动时不可见,如下所示

我尝试将详细信息活动背景设置为白色,但它不起作用

这就是我开始活动的方式

            Intent intent = new Intent(activity, NewsActivity.class);
            Bundle data = new Bundle();
            data.putParcelable(Constants.NEWS, news);
            ActivityOptionsCompat options = ActivityOptionsCompat.
                    makeSceneTransitionAnimation(activity, view, ViewCompat.getTransitionName(view));
            intent.putExtra(DATA, data);
            startActivity(intent,options.toBundle());

我的详细活动 xml

<androidx.constraintlayout.motion.widget.MotionLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" 
android:fitsSystemWindows="true"
tools:context=".ui.news.NewsActivity"
app:layoutDescription="@xml/collapsing_toolbar_news">

<ImageView
    android:id="@+id/toolbar_background"
    android:layout_width="match_parent"
    android:layout_height="?actionBarSize"
    android:scaleType="centerCrop"
    android:src="@color/colorPrimary"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.0"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />
<ImageView
    android:id="@+id/image"
    android:layout_width="0dp"
    android:layout_height="200dp"
    app:srcCompat="@color/colorPrimary"
    android:scaleType="centerCrop"
    android:transitionName="news"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintEnd_toEndOf="parent"/>

<ImageView
    android:id="@+id/back"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:minHeight="60dp"
    android:scaleType="centerInside"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:srcCompat="@drawable/ic_back" />
<TextView
    android:id="@+id/news_title"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:textSize="18sp"
    android:paddingTop="24dp"
    android:paddingStart="24dp"
    android:paddingEnd="24dp"
    android:paddingBottom="12dp"
    android:fontFamily="@font/montserrat_medium"
    android:textColor="@color/black"
    android:text="@string/app_name"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/image"
    app:layout_constraintEnd_toEndOf="parent" />
<androidx.core.widget.NestedScrollView
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:id="@+id/nested_scroll"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/news_title"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintBottom_toBottomOf="parent"
    android:paddingStart="24dp"
    android:paddingEnd="24dp"
    android:layout_marginTop="12dp"
    tools:showIn="@layout/activity_news">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">
        <TextView
            android:id="@+id/description"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="24dp"
            android:textSize="16sp"
            android:fontFamily="@font/kanit_regular"
            android:textColor="@color/dark_text"
            android:text="@string/large_text" />
    </LinearLayout>

    </androidx.core.widget.NestedScrollView>
</androidx.constraintlayout.motion.widget.MotionLayout>

我的回收站项目 xml

<com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="100dp"
    android:layout_marginTop="10dp"
    android:layout_marginBottom="10dp"
    android:orientation="vertical"
    app:cardCornerRadius="10dp"
    app:strokeColor="#BDBDBD"
    app:strokeWidth="1dp">
    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <com.islam.custom.roundedimageview.RoundedImageView
            android:id="@+id/news_image"
            android:transitionName="news"
            android:layout_width="match_parent"
            android:layout_height="100dp"
            android:scaleType="centerCrop"
            android:src="@drawable/ic_questions_background"
            app:riv_corner_radius="10dp" />
        <ImageView
            android:layout_width="match_parent"
            android:layout_height="100dp"
            android:scaleType="centerCrop"
            app:srcCompat="@drawable/ic_gradient_20"/>
        <ProgressBar
            android:id="@+id/progressbar"
            style="@style/progressbar"
            android:layout_gravity="center"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>
    </FrameLayout>
    <TextView
        android:id="@+id/news_title"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:fontFamily="@font/kanit_regular"
        android:maxLines="1"
        android:padding="14dp"
        android:ellipsize="end"
        android:text="@string/app_name"
        android:textColor="@color/white"
        android:textSize="16sp" />
    </com.google.android.material.card.MaterialCardView>

【问题讨论】:

  • 我首先看到的是两张图片的类型不同。
  • 看到您的评论后,我尝试将自定义 RoundedImageView 更改为 ImageView 并且相同的行为发生活动仍然不可见

标签: android android-activity android-animation shared-element-transition


【解决方案1】:

搜索后发现问题是因为我使用启动模式进行root活动

        android:launchMode="singleInstance"

但我不知道这如何使它无法正常工作。 我仍然需要为根活动设置启动模式

【讨论】:

  • 有趣的是,这种“行为”存在于 29 岁之前,但在 29 岁和 30 岁时可以正常工作
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-12-21
  • 1970-01-01
  • 2015-06-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多