gpt4 book ai didi

android - 水平机器人 :animateLayoutChanges ="true" Animation not smooth

转载 作者:太空宇宙 更新时间:2023-11-03 10:36:03 27 4
gpt4 key购买 nike

我有一个如下所示的动 Canvas 局

enter image description here

txt_billion 是动态显示的,带有 android:animateLayoutChanges="true"(下面的布局代码)。

注意 Hundred 正在跳跃(实际上所有的都在跳跃,只是 Hundred 更明显)。如何防止文字跳动?

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:padding="8dp"
android:background="#9f9"
android:text="Hundreds" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:padding="8dp"
android:background="#f9f"
android:text="Thousands" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:padding="8dp"
android:background="#0ff"
android:text="Millions" />
<TextView
android:id="@+id/txt_billion"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:padding="8dp"
android:visibility="gone"
android:background="#ff0"
android:text="Billions" />
</LinearLayout>

您可以从 https://github.com/elye/issue_horizontal_layout_animate 获取代码测试一下

最佳答案

尝试使用支持过渡 animateLayoutChanges

首先,从您的 XML 文件中删除 android:animateLayoutChanges="true"

之后,将 compile 'com.android.support:transition:25.4.0' 添加到您的应用依赖项中。

然后,在更改可见性之前添加这一行(来自 android.support.transition 包的 TransitionManager)

TransitionManager.beginDelayedTransition(parentOfAnimatedView);

为您的代码

public void clickMe(View view) {
TransitionManager.beginDelayedTransition((ViewGroup) billionText.getParent());
if (billionText.getVisibility() == View.GONE) {
billionText.setVisibility(View.VISIBLE);
} else {
billionText.setVisibility(View.GONE);
}
}

关于android - 水平机器人 :animateLayoutChanges ="true" Animation not smooth,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44653323/

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