Android:制作屏幕“闪光灯”白色 [英] Android: Make screen "flash" white

查看:141
本文介绍了Android:制作屏幕“闪光灯”白色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想让我的Android屏幕暂时闪现白色(只有一次)。它需要足够长,以便用户能够告诉屏幕确实变成了白色。

I want to make my android screen "flash" white temporarily (only once). It needs to be long enough that the user will be able to tell that the screen did in fact turn white.

用户将登陆屏幕,该屏幕将在5秒后闪烁白色,然后再次显示原始屏幕(可能从白色褪色)。

The user will land on a screen, which will flash white after 5 seconds, then display the original screen again (possibly fading from white).

最好的方法是什么?现在我正在创建一个占据整个屏幕并以编程方式显示和隐藏它的矩形。

What would be the best way to do this? Right now I am creating a rectangle that takes up the entire screen and programatically showing and hiding it.

推荐答案


  • 通过创建重叠( match_parent 大小)来添加前景ImageView并将 android:src 设置为白色drawable。

  • 将此视图的可见性设置为 android:visibility =gone

  • 当你想要显示白色闪光时,我建议使用动画来淡化白色闪光并显示它。

    • Add a foreground by creating an overlaying (match_parent size) ImageView and set android:src to a white drawable.
    • Set the visibility of this view to android:visibility="gone".
    • When you want to show the white flash, I recommend an animation to fade the white flash in and display it.
    • 这是一个基本的动画,它会淡化ImageView的drawable。淡出将与此相反。

      This is a basic animation which will fade in an ImageView's drawable. The fade out will be the reverse of this.

      public static void FadeIn(final ImageView v,
              final int begin_alpha, final int end_alpha, int time,
              final boolean toggleVisibility) {
      
          if (Integer.valueOf(android.os.Build.VERSION.SDK_INT) >= android.os.Build.VERSION_CODES.JELLY_BEAN)
              v.setImageAlpha(begin_alpha);
          else
              v.setAlpha(begin_alpha);
      
          if (toggleVisibility) {
              if (v.getVisibility() == View.GONE)
                  v.setVisibility(View.VISIBLE);
              else
                  v.setVisibility(View.GONE);
          }
      
          Animation a = new Animation() {
              @Override
              protected void applyTransformation(float interpolatedTime,
                      Transformation t) {
                  if (interpolatedTime == 1) {
                      if (Integer.valueOf(android.os.Build.VERSION.SDK_INT) >= android.os.Build.VERSION_CODES.JELLY_BEAN)
                          v.setImageAlpha(end_alpha);
                      else
                          v.setAlpha(end_alpha);
      
                      if (toggleVisibility) {
                          if (v.getVisibility() == View.GONE)
                              v.setVisibility(View.VISIBLE);
                          else
                              v.setVisibility(View.GONE);
                      }
                  } else {
                      int new_alpha = (int) (begin_alpha + (interpolatedTime * (end_alpha - begin_alpha)));
                      if (Integer.valueOf(android.os.Build.VERSION.SDK_INT) >= android.os.Build.VERSION_CODES.JELLY_BEAN)
                          v.setImageAlpha(new_alpha);
                      else
                          v.setAlpha(new_alpha);
                      v.requestLayout();
                  }
              }
      
              @Override
              public boolean willChangeBounds() {
                  return true;
              }
          };
      
          a.setDuration(time);
          v.startAnimation(a);
      }
      

      您可以使用android:foreground属性而不是创建新视图如果您正在使用framelayout并将不透明度从0(透明)切换为1(不透明)。 (注意:对于第一种方法,当Flash视图可见时,您将无法与其下的任何元素进行交互,这使得它比具有前景属性的FrameLayout更好。)但是,这很难实现。

      You could, instead of creating a new view, use the android:foreground property if you're using a framelayout and toggle the opacity from 0 (transparent) to 1 (opaque). (NB. For the first method, when the flash view is visible, you won't be able to interact with any elements under it, which makes this a better option than a FrameLayout with a foreground property). This is harder to implement, however.

      这篇关于Android:制作屏幕“闪光灯”白色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆