正在尝试在LinearLayout上管理显示/隐藏动画的此应用程序上工作。
我遇到的问题是,在切换可见性时,似乎第二次隐藏了任何孩子。
为了使我的故事更加清晰,此处是屏幕截图:
布局文件:
<TextView
android:id="@+id/tv_lecture"
style="@style/Text.Primary.Light"
android:singleLine="true" />
<LinearLayout
android:visibility="gone"
android:id="@+id/grades_container"
style="@style/Container.Vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="10"/>
</LinearLayout>
代码:
private void animate(final LinearLayout gradesContainer) {
if (gradesContainer.getVisibility() == View.GONE) {
gradesContainer.animate()
.translationY(gradesContainer.getHeight())
.alpha(1.0f)
.setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationStart(Animator animation) {
super.onAnimationStart(animation);
gradesContainer.setVisibility(View.VISIBLE);
gradesContainer.setAlpha(0.0f);
}
});
}
else {
gradesContainer.animate()
.translationY(0)
.alpha(0.0f)
.setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
gradesContainer.setVisibility(View.GONE);
}
});
}
}
在讲座TextView上,单击将触发该方法:animate()
那么,这里出了什么问题?不能弄清楚那就是为什么我要问你们。谢谢!
如果您只针对简单的动画。您可以继续并animateLayoutChanges
在xml中使用。
干杯! :)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句