【发布时间】:2021-03-03 19:38:29
【问题描述】:
我在我的项目中使用运动布局,当用户向上滚动时,我会隐藏我的 tabLayout,当用户向下滚动时,我会显示 tabLayout。 现在,我想在 tabLayout 出现时立即设置振动。 有什么方法可以设置监听器以结束运动布局?
这是我的动作描述:
<MotionScene xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<Transition
android:id="@+id/my_transition"
app:constraintSetEnd="@+id/ending_set"
app:constraintSetStart="@+id/starting_set"
app:duration="5000">
<OnSwipe
app:dragDirection="dragUp"
app:touchAnchorId="@+id/viewPager"
app:touchAnchorSide="top" />
</Transition>
<ConstraintSet android:id="@+id/starting_set">
<Constraint
android:id="@+id/viewPager"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tabLayout" />
<Constraint
android:id="@+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:alpha="1"
app:layout_constraintTop_toTopOf="parent" />
</ConstraintSet>
<ConstraintSet android:id="@+id/ending_set">
<Constraint
android:id="@+id/viewPager"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Constraint
android:id="@+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:alpha="0"
app:layout_constraintTop_toTopOf="parent" />
</ConstraintSet>
</MotionScene>
这是我的布局代码:
<?xml version="1.0" encoding="utf-8"?>
<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">
<androidx.constraintlayout.motion.widget.MotionLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:layoutDescription="@xml/news_motion"
tools:context=".main.news.AnalysisCategoryFragment">
<com.google.android.material.tabs.TabLayout
android:id="@+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#E6E6E6"
android:elevation="5dp"
app:layout_constraintTop_toTopOf="parent"
app:tabSelectedTextColor="@color/colorPrimaryDark"
app:tabTextColor="@color/gray" />
<androidx.viewpager2.widget.ViewPager2
android:elevation="5dp"
android:id="@+id/viewPager"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tabLayout" />
</androidx.constraintlayout.motion.widget.MotionLayout>
</layout>
【问题讨论】:
标签: android kotlin android-animation android-motionlayout