Android TransitionManager和ConstraintLayout的指南不起作用

Android TransitionManager和ConstraintLayout的指南不起作用,android,android-constraintlayout,android-transitions,Android,Android Constraintlayout,Android Transitions,我正在尝试使用TransitionManagerConstraintLayout和指南 这应该是直截了当的。从约束移动到底部父项,再移动到50%准则。 查看结果的视频。它将高度降低到1dp 我的第一个布局: <?xml version="1.0" encoding="utf-8"?><!-- ~ (c) Facebook, Inc. and its affiliates. Confidential and proprietary. --> <androi

我正在尝试使用
TransitionManager
ConstraintLayout
指南

这应该是直截了当的。从约束移动到底部父项,再移动到50%准则。 查看结果的视频。它将高度降低到1dp

我的第一个布局:

<?xml version="1.0" encoding="utf-8"?><!--
  ~ (c) Facebook, Inc. and its affiliates. Confidential and proprietary.
  -->

<android.support.constraint.ConstraintLayout
    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:id="@+id/root"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:ignore="BadClassUsageInResource-FrameLayout">

    <!-- foreground image -->
    <ImageView
        android:id="@+id/foreground_image"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:background="#ff0000"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</android.support.constraint.ConstraintLayout>

确保两个布局文件中都有相同id的指南。指南应该是水平的,而不是垂直的

您还应该从要转换到的布局中克隆ConstraintSet。(目前尚不清楚情况是否如此。)

做这些事情,它应该会起作用



我应该补充一点,带有TextView的第二个布局仅用于其约束。转换后,文本视图将不会出现在布局中。如果您确实希望显示文本视图,则需要将其添加到第一个布局。

这很有效!谢谢我没有意识到它需要在第一个布局中指定。我修改了布局名称以反映第二个布局。我正在尝试使TextView淡入+移动,因此它看起来像是滑入外观。但我得到的只是淡入。我试着用不同的位置将它添加到原始的主活动中,然后消失/不可见,但我得到的只是淡入。有可能进行淡入淡出和滑动吗?@Alon beginDelayedTransition非常容易使用,但确实做了一些假设。你应该能够得到一个幻灯片效果多一点的工作。看一看,寻找一些关于你可能如何处理这件事的线索。谢谢。我来看看。我成功地获得了淡入+移动只在进入屏幕动画。我会查看您的链接,以获得更精确的中心屏幕中的fave+移动…感谢您的推荐
<?xml version="1.0" encoding="utf-8"?><!--
  ~ (c) Facebook, Inc. and its affiliates. Confidential and proprietary.
  -->

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/root"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <!-- foreground image -->
    <ImageView
        android:id="@+id/foreground_image"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_margin="50dp"
        android:background="#ff0000"
        app:layout_constraintBottom_toTopOf="@+id/middle_guideline"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/text"
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:background="#9944FF"
        android:text="skdfjhskdjfhksjd"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="@+id/middle_guideline" />

    <android.support.constraint.Guideline
        android:id="@+id/middle_guideline"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        app:layout_constraintGuide_percent="0.5" />

</android.support.constraint.ConstraintLayout>
ConstraintSet constraintSet = new ConstraintSet();
constraintSet.clone(this, R.layout.second);
TransitionManager.beginDelayedTransition(mroot);
constraintSet.applyTo((ConstraintLayout) mroot);
val constraintSet = ConstraintSet()
// Clone from the layout that we are transitioning to.
constraintSet.clone(this, R.layout.activity_main_2)
TransitionManager.beginDelayedTransition(mroot)
constraintSet.applyTo(mroot as ConstraintLayout?)