由于某种原因,我无法使Constraintset动画执行任何操作。调用代码没有任何反应。即使我更改了tab
private fun moveNavigationBall(tab: BottombarItemView) {
val constraintSet = ConstraintSet()
constraintSet.clone(cl_bottombar_view_main)
constraintSet.connect(v_bottom_bar_circle_indicator.id, ConstraintSet.TOP, tab.id, ConstraintSet.TOP,0);
constraintSet.connect(v_bottom_bar_circle_indicator.id, ConstraintSet.BOTTOM, tab.id, ConstraintSet.BOTTOM,0);
constraintSet.connect(v_bottom_bar_circle_indicator.id, ConstraintSet.LEFT, tab.id, ConstraintSet.LEFT,0);
constraintSet.connect(v_bottom_bar_circle_indicator.id, ConstraintSet.RIGHT, tab.id, ConstraintSet.RIGHT,0);
constraintSet.applyTo(cl_bottombar_view_main)
val transition = ChangeBounds()
transition.interpolator = OvershootInterpolator()
TransitionManager.beginDelayedTransition(cl_bottombar_view_main, transition)
}
按下按钮时将调用此选项。选项卡因按下哪个按钮而异。我想做的就是将v_bottom_bar_circle_indicator
移动到每个标签的中间
视图
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
android:id="@+id/cl_bottombar_view_main"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:tools="http://schemas.android.com/tools"
>
<com.main.toucanmvp.mvp.components.bottombar.bottombaritem.BottombarItemView
android:id="@+id/biv_home"
android:layout_width="0dp"
android:layout_height="56dp"
app:bivBackground="@drawable/drawable_navigation_background_left"
app:bivIcon="@drawable/ic_home"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/biv_search"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintHorizontal_chainStyle="spread"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<com.main.toucanmvp.mvp.components.bottombar.bottombaritem.BottombarItemView
android:id="@+id/biv_search"
android:layout_width="0dp"
android:layout_height="56dp"
app:bivIcon="@drawable/ic_search"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/biv_clan"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/biv_home"
app:layout_constraintTop_toTopOf="parent"/>
<com.main.toucanmvp.mvp.components.bottombar.bottombaritem.BottombarItemView
android:id="@+id/biv_clan"
android:layout_width="0dp"
android:layout_height="56dp"
app:bivIcon="@drawable/ic_crown"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/biv_news"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/biv_search"
app:layout_constraintTop_toTopOf="parent"/>
<com.main.toucanmvp.mvp.components.bottombar.bottombaritem.BottombarItemView
android:id="@+id/biv_news"
android:layout_width="0dp"
android:layout_height="56dp"
app:bivIcon="@drawable/ic_news"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/biv_profile"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/biv_clan"
app:layout_constraintTop_toTopOf="parent"/>
<com.main.toucanmvp.mvp.components.bottombar.bottombaritem.BottombarItemView
android:id="@+id/biv_profile"
android:layout_width="0dp"
android:layout_height="56dp"
app:bivBackground="@drawable/drawable_navigation_background_right"
app:bivIcon="@drawable/ic_profile"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/biv_news"
app:layout_constraintTop_toTopOf="parent"/>
<FrameLayout
android:id="@+id/v_bottom_bar_circle_indicator"
android:layout_width="34dp"
android:layout_height="34dp"
android:background="@drawable/drawable_circle_navigation_bar"
app:layout_constraintBottom_toBottomOf="@+id/biv_home"
app:layout_constraintEnd_toEndOf="@+id/biv_home"
app:layout_constraintStart_toStartOf="@+id/biv_home"
app:layout_constraintTop_toTopOf="@+id/biv_home"/>
</android.support.constraint.ConstraintLayout>
答案 0 :(得分:1)
首先,为了动画化约束的变化,您需要放置
constraintSet.applyTo(cl_bottombar_view_main)
之后
TransitionManager.beginDelayedTransition(cl_bottombar_view_main, transition)
第二,在XML布局文件中,您要为要设置动画的视图(start
)使用end
和v_bottom_bar_circle_indicator
约束,但是在代码中,您正在使用{{1} }和ConstraintSet.LEFT
,它们是不同的。您需要将它们分别更改为ConstraintSet.RIGHT
和ConstraintSet.START
。
在这种情况下可能或可能无关紧要的第三件事是,您将ConstraintSet.END
的边距设置为每个0
函数的最后一个参数。 connect()
文档说,边距必须为正数,因此将其设置为ConstraintSet
时可能无法达到预期的效果。我建议在这种情况下使用不带margin参数的签名。