如何在Android中创建背景色的屏幕擦除效果

3
我有一张带透明空间的前景图片,你可以透过它看到背景颜色,开始为白色。我需要创建一个擦拭效果,让颜色从左到右移动,从白色变成蓝色。不只是简单的淡入淡出过渡。它应该像一个蓝色的窗帘被拉过屏幕,慢慢改变透过图片中心的颜色。
目前我使用了ValueAnimator来设置基本的淡入淡出效果,但要求是这种擦拭效果。如何创建这个窗帘擦拭效果?
要澄清的是,我想要的效果是一个实色窗帘被缓慢地拉过白色屏幕,最终只剩下蓝色。
    <FrameLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/white"
        android:foreground="@drawable/loading_page_4"
        android:id="@+id/splash_color_layout" >
    </FrameLayout>

如果您的意思是应用渐变,请参考此链接:https://dev59.com/lm025IYBdhLWcg3wfmDw - Drilon Blakqori
谢谢您的评论!但我不是在寻找渐变效果。我想要创建一个效果(我对此还很陌生,不确定它是否需要成为动画或其他什么),其中有一个纯白色。然后从左侧进入一个纯蓝色,到最后覆盖整个屏幕上的白色,只留下蓝色。所以想象一下一个白色屏幕,一个完全蓝色的帘子被缓慢地拉过来覆盖屏幕。 - Chris Wilson
1个回答

1

有几种方法可以解决这个问题,但最简单和最简单的方法是向您的框架添加一个子视图。

 <FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white"
    android:foreground="@drawable/loading_page_4"
    android:id="@+id/splash_color_layout" >

    <View
        android:id="@+id/wipe_animation_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/blue"
        android:visibility="invisible" />
</FrameLayout>

然后,当你想要启动动画时(必须在视图布局完成后执行):
wipeAnimationView.setVisibility(View.VISIBLE);
wipeAnimationView.setTranslationX(-wipeAnimationView.getWidth());
wipeAnimationView.animate().translationX(0.0f).start();

需要注意的是,如果在屏幕布局之前开始动画,视图的宽度将为0,没有效果。您应该使用view.post(() -> runAnimation());


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接