我正在尝试使用TransitionManager
ConstraintLayout
和Guideline
从全屏显示到半屏显示>
这应该很简单。从约束到下层父级,再到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>
我的第二个布局:
<?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);
我正在尝试使用TransitionManager ConstraintLayout和Guideline将全屏视图变成半屏视图,这应该很简单。从约束移到下层父级,再到50%...
请确保准则在两个布局文件中都具有相同的ID。准则应该是水平的,而不是垂直的。