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

标签 android android-layout android-animation android-layout-weight android-layoutparams

我有一个如下所示的动 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/

相关文章:

android - 在新项目中安装应用程序时会自动授予危险权限 [React Native - Android]

android - getExternalFilesDir(null) 为某些用户返回 null

android - 以编程方式将项目添加到相对布局

android - 适用于 Android 的通用补间引擎

android - Paint 对象的动画颜色

android - Android动画结束后更新TextView

android - 广告未针对正确的应用程序包名称展示

java - TextView 中的文本对齐方式

android - 在 dimensions.xml 中使用 FILL_PARENT

java - 如何在 Android 中使用 RecyclerView?