首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Android中的背景色上创建屏幕擦除效果?

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

Stack Overflow用户
提问于 2016-01-08 17:02:13
回答 1查看 447关注 0票数 3

我有一个前景图像,中间有一个透明的空间,这样你就可以通过它看到背景颜色,从白色开始。我需要创建一个擦除效果,其中颜色变化从白色到蓝色,从左到右在屏幕上移动。不仅仅是从一个消失到另一个。它需要像一个蓝色的窗帘被拉过屏幕,慢慢改变颜色出现在中间的图像。

目前,我已将其设置为使用ValueAnimator的基本淡出效果,但所需的是这种擦除效果。我怎样才能创造这个窗帘擦拭的效果?

为了澄清我正在寻找的效果是一个坚实的彩色窗帘被慢慢拉过一个白色的屏幕,所以在最后,所有的是蓝色。

代码语言:javascript
复制
    <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>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-01-08 19:44:15

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

代码语言:javascript
复制
 <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>

然后,当您想要启动动画时(必须在视图放置之后完成):

代码语言:javascript
复制
wipeAnimationView.setVisibility(View.VISIBLE);
wipeAnimationView.setTranslationX(-wipeAnimationView.getWidth());
wipeAnimationView.animate().translationX(0.0f).start();

重要的是要注意的是,如果您是启动动画之前,屏幕布局,视图的宽度将是0,它将没有任何影响。你应该view.post(() -> runAnimation());

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34682305

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档