【发布时间】:2021-04-09 11:21:01
【问题描述】:
我是MotionLayout 的新手。我遵循了一个简单的示例,其中MotionLayout 包含一个元素,例如Button,这很容易为它生成MotionScene。但是我有一个MotionLayout,其中有几个元素。
布局是这样的-
<?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/details_view_scene">
<ScrollView
android:id="@+id/scroll_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/details_image"
style="@style/detailsImage"
app:layout_constraintDimensionRatio="h,16:9"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.textview.MaterialTextView
android:id="@+id/name_label"
style="@style/textTitle"
android:text="@string/name"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/details_image" />
<com.google.android.material.textview.MaterialTextView
android:id="@+id/name_value"
style="@style/textSubTitle"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/name_label" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/like_button"
style="@style/floatingButton"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:srcCompat="@drawable/ic_profile_like" />
<ImageView
android:id="@+id/like_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_profile_like"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:visibility=“invisible”/>
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
</androidx.constraintlayout.motion.widget.MotionLayout>
问题是,当按下 ID 为 like_button 的浮动操作按钮时,我希望 ID 为 like_image 的图像视图可见,并且应该从浮动操作按钮转换到 ID 为 details_image 的顶部图像视图。
MotionLayout 可以做到这一点吗?
【问题讨论】:
标签: android kotlin android-constraintlayout androidx android-motionlayout