【发布时间】:2020-07-04 22:57:39
【问题描述】:
我试图实现我们在协调器布局中所做的动画,例如使用运动布局折叠工具栏。我有以下带有工具栏(框架布局)、图像视图和滚动视图的运动布局。工具栏的高度随着滚动视图的滑动而增加。但是在滚动视图在工具栏下移动后,它的高度(阴影)不再可见。我不确定为什么阴影不可见。
<?xml version="1.0" encoding="utf-8"?>
<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"
app:layoutDescription="@xml/activity_main_scene"
app:showPaths="true"
tools:context=".MainActivity">
<ImageView
android:id="@+id/iv_top"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:contentDescription="@string/top"
android:scaleType="centerCrop"
android:src="@drawable/test_vector"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/toolbar" />
<androidx.core.widget.NestedScrollView
android:id="@+id/scroll_view"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/iv_top">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:text="@string/stub"
android:textSize="24sp" />
</androidx.core.widget.NestedScrollView>
<FrameLayout
android:id="@+id/toolbar"
android:layout_width="0dp"
android:layout_height="60dp"
android:background="@color/colorPrimary"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.motion.widget.MotionLayout>
我的动态场景是:
<?xml version="1.0" encoding="utf-8"?>
<MotionScene xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<ConstraintSet android:id="@+id/start">
</ConstraintSet>
<ConstraintSet android:id="@+id/end">
<Constraint
android:id="@id/iv_top"
android:layout_height="0dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Constraint
android:id="@id/toolbar"
android:layout_width="0dp"
android:layout_height="60dp"
android:elevation="20dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</ConstraintSet>
<Transition
app:constraintSetEnd="@id/end"
app:constraintSetStart="@+id/start"
app:duration="1000">
<OnSwipe
app:touchAnchorId="@+id/scroll_view"
app:touchAnchorSide="top" />
</Transition>
</MotionScene>
【问题讨论】:
标签: android android-motionlayout