#android #kotlin #android-layout #animation #android-motionlayout
Вопрос:
Мы работали над проектом для Android, и мы столкнулись с проблемой анимации в MotionLayout при прокрутке RecyclerView (вы можете видеть на видео).
после прокрутки в любом месте на экране анимация в порядке, но после прокрутки на панели приложений запускается анимация, но так странно.
Я добавил картинку и видео от архитектора пользовательского интерфейса, чтобы избежать путаницы.
Фрагмент профиля.кт
private fun coordinateMotion() { val appBarLayout: AppBarLayout? = binding.appbarLayout val motionLayout: MotionLayout = binding.profileHeaderInfo as MotionLayout val p = DecimalFormat("0.0"); val listener = AppBarLayout.OnOffsetChangedListener { unused, verticalOffset -gt; val seekPosition = -verticalOffset / appBarLayout?.totalScrollRange!!.toFloat() motionLayout.progress = seekPosition Log.d(TAG, "coordinateMotion: $seekPosition") } appBarLayout?.addOnOffsetChangedListener(listener) }
Фрагмент профиля:
lt;?xml version="1.0" encoding="utf-8"?gt; lt;layout 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"gt; lt;androidx.coordinatorlayout.widget.CoordinatorLayout android:layout_width="match_parent" android:layout_height="match_parent"gt; lt;androidx.core.widget.NestedScrollView android:layout_width="match_parent" android:fillViewport="true" android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior"gt; lt;include android:id="@ id/profile_include" layout="@layout/profile_layout_content" /gt; lt;/androidx.core.widget.NestedScrollViewgt; lt;com.google.android.material.appbar.AppBarLayout android:id="@ id/appbar_layout" android:layout_width="match_parent" android:layout_height="wrap_content"gt; lt;androidx.constraintlayout.motion.widget.MotionLayout android:id="@ id/profile_header_info" android:layout_width="match_parent" app:motionDebug="SHOW_PATH" android:layout_height="wrap_content" android:minHeight="80dp" android:background="@color/primary" app:layout_scrollFlags="scroll|enterAlways|snap|exitUntilCollapsed" app:layoutDescription="@xml/fragment_profile_xml_profile_header_info_scene" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent"gt; ..... lt;/androidx.constraintlayout.motion.widget.MotionLayoutgt; lt;/com.google.android.material.appbar.AppBarLayoutgt; lt;/androidx.coordinatorlayout.widget.CoordinatorLayoutgt;
fragment_profile_xml_profile_header_info_scene
lt;?xml version="1.0" encoding="utf-8"?gt; lt;MotionScene xmlns:android="http://schemas.android.com/apk/res/android" xmlns:motion="http://schemas.android.com/apk/res-auto"gt; lt;ConstraintSet android:id="@ id/start"gt; lt;Constraint android:id="@ id/profile_user_name" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginStart="16dp" android:layout_marginEnd="24dp" motion:layout_constraintEnd_toEndOf="parent" motion:layout_constraintStart_toEndOf="@ id/profile_image" motion:layout_constraintTop_toTopOf="@ id/profile_image"gt; lt;/Constraintgt; lt;Constraint android:id="@ id/profile_user_login" android:layout_width="0dp" android:layout_height="wrap_content" motion:layout_constraintBottom_toTopOf="@ id/profile_user_desc" motion:layout_constraintEnd_toEndOf="@ id/profile_user_name" motion:layout_constraintStart_toStartOf="@ id/profile_user_name" motion:layout_constraintTop_toBottomOf="@ id/profile_user_name"gt; lt;/Constraintgt; lt;Constraint android:id="@ id/profile_user_desc" android:layout_width="0dp" android:layout_height="wrap_content" motion:layout_constraintBottom_toBottomOf="@ id/profile_image" motion:layout_constraintEnd_toEndOf="@ id/profile_user_login" motion:layout_constraintStart_toStartOf="@ id/profile_user_login" motion:layout_constraintTop_toBottomOf="@ id/profile_user_login" /gt; lt;Constraint android:id="@ id/profile_image" android:layout_width="75dp" android:layout_height="75dp" android:layout_marginStart="24dp" android:layout_marginTop="24dp" android:layout_marginEnd="16dp" android:elevation="10dp" motion:layout_constraintEnd_toEndOf="parent" motion:layout_constraintHorizontal_bias="0.0" motion:layout_constraintStart_toStartOf="parent" motion:layout_constraintTop_toTopOf="parent" /gt; lt;/ConstraintSetgt; lt;ConstraintSet android:id="@ id/end"gt; lt;Constraint android:id="@ id/profile_user_name" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginStart="16dp" motion:layout_constraintStart_toEndOf="@ id/profile_image" motion:layout_constraintTop_toTopOf="@ id/profile_image"gt; lt;CustomAttribute motion:attributeName="textSize" motion:customDimension="10sp" /gt; lt;/Constraintgt; lt;Constraint android:id="@ id/profile_user_login" android:layout_width="0dp" android:layout_height="wrap_content" motion:layout_constraintBottom_toBottomOf="@id/profile_user_name" motion:layout_constraintStart_toEndOf="@ id/profile_user_name" motion:layout_constraintTop_toTopOf="@id/profile_user_name" motion:layout_constraintEnd_toEndOf="parent"gt; lt;CustomAttribute motion:attributeName="textSize" motion:customDimension="8sp" /gt; lt;/Constraintgt; lt;Constraint android:id="@ id/profile_user_desc" android:layout_width="0dp" android:layout_height="wrap_content" motion:layout_constraintBottom_toBottomOf="@ id/profile_image" motion:layout_constraintEnd_toEndOf="@ id/profile_user_login" motion:layout_constraintStart_toStartOf="@ id/profile_user_name" motion:layout_constraintTop_toBottomOf="@ id/profile_user_name" /gt; lt;Constraint android:id="@ id/profile_image" android:layout_width="50dp" android:layout_height="50dp" android:layout_marginStart="24dp" android:layout_marginEnd="16dp" android:layout_marginBottom="16dp" android:elevation="10dp" motion:layout_constraintBottom_toBottomOf="parent" motion:layout_constraintEnd_toEndOf="parent" motion:layout_constraintHorizontal_bias="0.0" motion:layout_constraintStart_toStartOf="parent" motion:layout_constraintTop_toTopOf="parent" /gt; lt;Constraint android:id="@ id/profile_header_divider" android:layout_width="0dp" android:layout_height="1dp" android:layout_marginTop="0dp" motion:layout_constraintEnd_toEndOf="@ id/profile_user_desc" motion:layout_constraintStart_toStartOf="@ id/profile_image" motion:layout_constraintTop_toBottomOf="@ id/profile_user_desc" /gt; lt;Constraint android:id="@ id/profile_header_company_icon" android:layout_width="20dp" android:layout_height="20dp" motion:layout_constraintStart_toStartOf="@ id/profile_header_divider" motion:layout_constraintTop_toTopOf="parent" /gt; lt;/ConstraintSetgt; lt;Transition motion:constraintSetEnd="@ id/end" motion:constraintSetStart="@id/start" motion:duration="1000"gt; lt;KeyFrameSetgt; lt;KeyAttribute android:alpha="0" motion:framePosition="100" motion:motionTarget="@ id/profile_header_divider" /gt; lt;/KeyFrameSetgt; lt;KeyFrameSetgt; lt;!-- lt;KeyAttribute--gt; lt;!-- android:alpha="0"--gt; lt;!-- motion:framePosition="100"--gt; lt;!-- motion:motionTarget="@ id/profile_user_desc" /gt;--gt; lt;KeyAttribute android:alpha="0" motion:framePosition="100" motion:motionTarget="@ id/profile_header_company" /gt; lt;KeyAttribute android:alpha="0" motion:framePosition="100" motion:motionTarget="@ id/profile_header_location" /gt; lt;KeyAttribute android:alpha="0" motion:framePosition="100" motion:motionTarget="@ id/profile_header_create_at" /gt; lt;KeyAttribute android:alpha="0" motion:framePosition="100" motion:motionTarget="@ id/profile_header_company_icon" /gt; lt;KeyAttribute android:alpha="0.0" motion:framePosition="100" motion:motionTarget="@ id/profile_header_location_icon" /gt; lt;KeyAttribute android:alpha="0" motion:framePosition="100" motion:motionTarget="@ id/profile_header_create_at_icon" /gt; lt;/KeyFrameSetgt; lt;OnSwipe /gt; lt;/Transitiongt; lt;/MotionScenegt;