MotionLayout左右滑动动画问题



当我添加layoutDescription时,layout-width不再工作,我正在创建一个用户可以向左或向右滑动的运动布局。我希望能够在滑动时调整布局的android:layout_width的大小。这是我的MotionSceneMotionLayout的XML

<androidx.constraintlayout.motion.widget.MotionLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layoutDescription="@xml/table_view_odd_list_shuffle"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@id/guideline5"
app:layout_constraintTop_toBottomOf="@id/constraint_layout_spinners">
<RelativeLayout
android:id="@+id/relative_layout_odds_column"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/constraint_layout_odds"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/table_view_recycle_view_odds_1"
android:layout_width="0dp"
android:layout_height="0dp"
android:nestedScrollingEnabled="false"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/table_view_recycle_view_odds_2"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/table_view_recycle_view_odds_2"
android:layout_width="0dp"
android:layout_height="0dp"
android:nestedScrollingEnabled="false"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/table_view_recycle_view_odds_1"
app:layout_constraintTop_toTopOf="parent" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/guideline6"
android:layout_width="0dp"
android:layout_height="0dp"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.5"
app:layout_constraintTop_toBottomOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</RelativeLayout>
</androidx.constraintlayout.motion.widget.MotionLayout>

MotionScene 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">
<!-- center to left-->
<Transition
motion:constraintSetEnd="@id/left"
motion:constraintSetStart="@id/center"
motion:duration="200">
<OnSwipe
motion:dragDirection="dragLeft"
motion:touchAnchorId="@id/relative_layout_odds_column"
motion:touchAnchorSide="left" />
</Transition>
<!-- center to right -->
<Transition
motion:constraintSetEnd="@id/right"
motion:constraintSetStart="@id/center"
motion:duration="200">
<OnSwipe
motion:dragDirection="dragRight"
motion:touchAnchorId="@id/relative_layout_odds_column"
motion:touchAnchorSide="right" />
</Transition>
<ConstraintSet android:id="@+id/center">
<Constraint
android:id="@id/relative_layout_odds_column"
android:layout_width="match_parent"
android:layout_height="match_parent"
motion:layout_constraintEnd_toEndOf="parent"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintStart_toStartOf="parent"
motion:layout_constraintTop_toTopOf="parent">
<PropertySet android:alpha="1" />
</Constraint>
</ConstraintSet>
<!-- place the view on left-->
<ConstraintSet android:id="@+id/left">
<Constraint
android:id="@id/relative_layout_odds_column"
android:layout_width="10dp"
android:layout_height="match_parent"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintStart_toStartOf="parent"
motion:layout_constraintTop_toTopOf="parent">
<PropertySet android:alpha="1" />
</Constraint>
</ConstraintSet>
<!-- place the view on right-->
<ConstraintSet android:id="@+id/right">
<Constraint
android:id="@id/relative_layout_odds_column"
android:layout_width="10dp"
android:layout_height="match_parent"
motion:layout_constraintEnd_toEndOf="parent"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintTop_toTopOf="parent">
<PropertySet android:alpha="1" />
</Constraint>
</ConstraintSet>

</MotionScene>

场景文件中的约束定义存在问题。使用下面的代码,而不是现在的代码。

<Constraint
android:id="@id/relative_layout_odds_column"
android:layout_width="0dp"
android:layout_height="0dp"
motion:layout_constraintEnd_toEndOf="parent"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintStart_toStartOf="parent"
motion:layout_constraintTop_toTopOf="parent">
<PropertySet android:alpha="1" />
</Constraint>
</ConstraintSet>
<!-- place the view on left-->
<ConstraintSet android:id="@+id/left">
<Constraint
android:id="@id/relative_layout_odds_column"
android:layout_width="10dp"
android:layout_height="0dp"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintStart_toStartOf="parent"
motion:layout_constraintTop_toTopOf="parent">
<PropertySet android:alpha="1" />
</Constraint>
</ConstraintSet>
<!-- place the view on right-->
<ConstraintSet android:id="@+id/right">
<Constraint
android:id="@id/relative_layout_odds_column"
android:layout_width="10dp"
android:layout_height="0dp"
motion:layout_constraintEnd_toEndOf="parent"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintTop_toTopOf="parent">
<PropertySet android:alpha="1" />
</Constraint>
</ConstraintSet>

最新更新