我正在使用重要的日历视图。我在日历下方有一行,当我向下滑动日历模式时,应该使用动画从周视图更改为月视图。
我正在尝试使用运动布局来实现上述目标。但是我不知道如何在运动布局的开始和结束之间更改日历模式。
下面是我的xml:
<androidx.constraintlayout.motion.widget.MotionLayout
android:id="@+id/motionLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layoutDescription="@xml/activity_main_scene"
app:layout_constraintTop_toTopOf="parent">
<com.prolificinteractive.materialcalendarview.MaterialCalendarView
android:id="@+id/calendarView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:mcv_calendarMode="week"
app:mcv_selectionColor="#00F"
app:mcv_showOtherDates="all"
app:mcv_showWeekDays="true" />
<View
android:id="@+id/line"
android:layout_width="200dp"
android:layout_height="2dp"
android:layout_marginTop="10dp"
android:background="@color/colorPrimary"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/calendarView" />
</androidx.constraintlayout.motion.widget.MotionLayout>
下面是我的动作布局场景:
<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/calendarView" />
</ConstraintSet>
<ConstraintSet android:id="@+id/end">
<Constraint
android:id="@id/calendarView"
layout_height="200dp />
</ConstraintSet>
<Transition
app:constraintSetEnd="@id/end"
app:constraintSetStart="@+id/start"
app:duration="500">
<OnSwipe
app:dragDirection="dragDown"
app:touchAnchorId="@+id/line" />
</Transition>
</MotionScene>
任何人都可以让我知道如何在动画开始和动画结束之前更改日历模式
可以使用以下代码更改日历模式:
calendarView.state().edit()
.setCalendarDisplayMode(CalendarMode.MONTHS)
.commit()