Ely*_*lye 5 android android-animation android-layout android-layout-weight android-layoutparams
我有一个动画布局,如下所示
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>
Run Code Online (Sandbox Code Playgroud)
您可以从https://github.com/elye/issue_horizo ntal_layout_animate 获取代码进行测试
尝试使用支持转换animateLayoutChanges
首先,删除android:animateLayoutChanges="true"首先,从 XML 文件中
之后,添加compile 'com.android.support:transition:25.4.0'到您的应用程序依赖项。
然后,在更改可见性之前添加此行(来自 android.support.transition 包的 TransitionManager)
TransitionManager.beginDelayedTransition(parentOfAnimatedView);
Run Code Online (Sandbox Code Playgroud)
对于你的代码
public void clickMe(View view) {
TransitionManager.beginDelayedTransition((ViewGroup) billionText.getParent());
if (billionText.getVisibility() == View.GONE) {
billionText.setVisibility(View.VISIBLE);
} else {
billionText.setVisibility(View.GONE);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2074 次 |
| 最近记录: |