直播系统源代码实现RecyclerView折叠展开动画

直播系统源代码实现RecyclerView折叠展开动画的相关代码
首先来看看布局文件

<?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:id="@+id/motionContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
app:layoutDescription="@xml/motion_list_rv_item_scene">

<LinearLayout
android:id="@+id/box_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="86dp">
....
</LinearLayout>
</LinearLayout>

<View
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="@color/blue_magic" />
</LinearLayout>

<View
android:id="@+id/view2"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="@id/box_content"
android:background="#eaeaef" />
</androidx.constraintlayout.motion.widget.MotionLayout>

 

直播系统源代码的布局文件很简单,只不过你可能会注意到,我们对 LinearLayout并没有添加任何约束,原因在于:我们会在 MotionScene 中声明 ConstraintSet,里面将包含该 LinearLayout 的“运动”起始点和终点的约束信息。
当然你也可以在直播系统源代码的布局文件中对其加以约束,但 MotionScene 中对于控件约束的优先级会高于布局文件中的设定。这里我们通过 layoutDescription 来为 MotionLayout 设置它的 MotionScene 为 motion_list_rv_item_scene,接下来就让我们一睹 MotionScene 的芳容:
动画文件

<?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">
<Constraint
android:id="@id/box_content"
android:layout_width="0dp"
android:layout_height="86dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</ConstraintSet>

<ConstraintSet android:id="@+id/end">
<Constraint
android:id="@id/box_content"
android:layout_width="0dp"
android:layout_height="186dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</ConstraintSet>

<Transition
app:constraintSetEnd="@id/end"
app:constraintSetStart="@+id/start"
app:duration="500"
app:motionInterpolator="easeInOut">
</Transition>
</MotionScene>

以上就是直播系统源代码实现RecyclerView折叠展开动画的相关代码, 更多内容欢迎关注之后的文章

posted @ 2021-08-31 14:17  云豹科技-苏凌霄  阅读(92)  评论(0编辑  收藏  举报