gpt4 book ai didi

android - 约束布局动画不起作用

转载 作者:行者123 更新时间:2023-11-29 23:49:56 25 4
gpt4 key购买 nike

出于某种原因,我无法让约束集动画做任何事情。调用代码时没有任何反应。即使我更改了 tab

的 id
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>

最佳答案

首先,为了动画化你需要放置的约束的变化

constraintSet.applyTo(cl_bottombar_view_main)

之后

TransitionManager.beginDelayedTransition(cl_bottombar_view_main, transition)

其次,在您的 XML 布局文件中,您正在为要设置动画的 View (v_bottom_bar_circle_indicator) 使用 startend 约束,但在您使用的代码 ConstraintSet.LEFTConstraintSet.RIGHT,它们是不同的。您需要将它们分别更改为 ConstraintSet.STARTConstraintSet.END

第三件事,在这种情况下可能重要也可能不重要,是您将 0 的边距设置为每个 connect() 函数的最后一个参数。 ConstraintSet 文档说边距必须是正数,因此当设置为 0 时它可能不会按预期运行。在这种情况下,我建议使用不带 margin 参数的签名。

关于android - 约束布局动画不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50972432/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com