android - MotionLayout Android中的RecyclerView问题
问题描述
我面临的问题是回收器视图在转换后无法正确呈现。
请在这里找到视频
ConstraintLayout 版本:2.0.4 RecyclerView 版本:1.1.0
活动主页.xml
<?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/homeParent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorWhite"
app:layoutDescription="@xml/activity_home_scene">
<FrameLayout
android:id="@+id/homeSearchContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/all_margin_16dp"
android:layout_marginTop="@dimen/all_margin_16dp"
android:layout_marginEnd="@dimen/all_margin_16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/collegeLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/homeSearchContainer">
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/homeCollegeNameTv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/all_padding_8dp"
android:fontFamily="@font/product_sans_regular"
android:textColor="@color/colorBlack"
android:textSize="@dimen/all_font_16sp"
android:maxLines="2"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/homeCategoriesRv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@+id/collegeLayout"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/tabContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/homeCategoriesRv">
<com.google.android.material.tabs.TabLayout
android:id="@+id/homeTabs"
style="@style/AppTheme.TabLayout"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_gravity="start"
android:background="@color/colorWhite"
app:tabGravity="fill"
app:tabMode="fixed" />
</com.google.android.material.appbar.AppBarLayout>
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:id="@+id/homeContainer"
android:layout_width="match_parent"
android:layout_height="@dimen/all_height_0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tabContainer">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/refreshLayout"
android:layout_width="match_parent"
android:layout_height="@dimen/all_height_0dp"
android:visibility="gone"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/noNetIv"
android:layout_width="@dimen/all_width_200dp"
android:layout_height="@dimen/all_height_200dp"
android:layout_margin="@dimen/all_margin_8dp"
app:tint="@color/colorPrimaryDark"
app:srcCompat="@drawable/ic_wifi_off"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
<androidx.appcompat.widget.AppCompatTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/home_no_internet"
android:textColor="@color/colorMain"
android:textSize="@dimen/all_font_16sp"
android:fontFamily="@font/product_sans_regular"
android:gravity="center"
android:layout_margin="@dimen/all_margin_8dp"
app:layout_constraintTop_toBottomOf="@+id/noNetIv"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/homeVp"
android:layout_width="match_parent"
android:layout_height="@dimen/all_height_0dp"
android:orientation="horizontal"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/btnAddPost"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="visible"
android:layout_marginEnd="@dimen/all_margin_16dp"
android:layout_marginBottom="@dimen/all_margin_56dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:srcCompat="@drawable/ic_add"
tools:ignore="ContentDescription" />
</androidx.constraintlayout.motion.widget.MotionLayout>
activity_home_scene.xml
<?xml version="1.0" encoding="utf-8"?>
<MotionScene
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:motion="http://schemas.android.com/apk/res-auto">
<Transition
motion:constraintSetStart="@+id/start"
motion:constraintSetEnd="@id/end"
motion:duration="250"
motion:motionInterpolator="linear" />
<ConstraintSet android:id="@+id/start">
</ConstraintSet>
<ConstraintSet android:id="@+id/end">
<Constraint
android:id="@id/homeSearchContainer"
android:visibility="gone"/>
<Constraint
android:id="@id/collegeLayout"
android:visibility="gone"/>
<Constraint
android:id="@id/homeCategoriesRv"
android:visibility="gone"/>
<Constraint
android:id="@+id/tabContainer"
android:visibility="gone"/>
<Constraint
android:id="@+id/btnAddPost"
android:visibility="gone"/>
<Constraint
android:id="@id/homeContainer"
motion:layout_constraintTop_toTopOf="parent"
motion:layout_constraintStart_toStartOf="parent"
motion:layout_constraintEnd_toEndOf="parent"
motion:layout_constraintBottom_toBottomOf="parent"/>
<Constraint
android:id="@id/homeVp"
motion:layout_constraintTop_toTopOf="parent"
motion:layout_constraintStart_toStartOf="parent"
motion:layout_constraintEnd_toEndOf="parent"
motion:layout_constraintBottom_toBottomOf="parent"/>
</ConstraintSet>
</MotionScene>
在我的 HomeActivity.kt 我调用motionlayout转换如下
fun hideViews() {
binding.homeParent.transitionToEnd()
}
fun showViews() {
binding.homeParent.transitionToStart()
}
我尝试了以下两件事:
motion:layoutDuringTransition="honorRequest"
binding.homeCategoriesRv.scrollBy(0,0)
请帮忙。任何想法,将不胜感激!
解决方案
推荐阅读
- php - Laravel Nova v2.8.0 : 自定义动作标签
- flutter - 使用 ImmediateMultiDragGestureRecognizer 记录 Touches 时,如何从正确的上下文中偏移?
- google-cloud-platform - 如何在谷歌云中保存一些规则或配置,然后调用它来处理云函数中的 pubsub 主题数据?
- sql - 在 SQL 中,获取列 A 中具有相同值且列 B 中只有非空值的所有行
- javascript - 我需要在 div 中渲染脚本
- excel - VBA过滤器包含日期的部分字符串
- flutter - 网络图像到 base 64 颤动
- r - R闪亮仪表板中的动态重复条件面板
- git - 将文件夹转换为git子模块后,如何轻松切换分支
- javascript - 带有弹性儿童的 Flex wrap