首页 > 解决方案 > 如何在 ANDROID 中为 View.GONE 到 View.VISIBLE 的视图设置动画

问题描述

这是我的布局 xml 的结构:

<RelativeView>

    <ScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

        <...>

    </ScrollView>

    <View
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:visibility="gone" />

</RelativeView>

当我希望视图出现时,我View.VISIBLE在 java 文件中使用。我这样做是因为我不希望 View 与 ScrollView 重叠。

现在,我想为视图设置动画View.GONEView.VISIBLE使其看起来不错。 我知道动画可以从 Alpha 0 到 1 完成。 但是是否可以从 toView.GONE动画View.VISIBLE

标签: androidandroid-studioandroid-layoutandroid-animation

解决方案


添加android:animateLayoutChanges="true"到您的 xml 文件中,如果您想在您的 java 类中淡出使用,并且如果您想要淡入使用。view.animate().alpha(0.0f);view.animate().alpha(1.0f);


推荐阅读