【发布时间】:2017-06-20 12:39:15
【问题描述】:
我的布局如下所示
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 获取代码进行测试
【问题讨论】:
-
在哪个设备上?哪个安卓版本?是否启用了硬件加速?
-
任何设备。我试过 Nexus 5 的 Android 模拟器,Nougat
-
模拟器不是设备。先在设备上试试。它应该有很大的不同。
-
它也发生在实际设备上。所以我创建了一个小样本作品来证明这个问题。尝试使用文本重心创建水平布局,并且 animateLayouChange 为 true。您应该会看到这种情况发生。
-
抱歉,无法重现,在我的 OnePlus One 上运行完全流畅
标签: android android-layout android-animation android-layout-weight android-layoutparams