【问题标题】:Shading sub Layout in androidandroid中的着色子布局
【发布时间】:2016-03-19 05:27:53
【问题描述】:

我陷入了使用淡入淡出动画后无法保持子布局淡出的状态

FrameLayout mapLayout = (FrameLayout)findViewById(R.id.mapLayout);

Animation fadeAnim = AnimationUtils.loadAnimation(this, android.R.anim.fade_out);
mapLayout.startAnimation(fadeAnim);

请指导我如何在 android 中实现这一点。当我单击“暂停”按钮并反转效果时,会出现此动画和阴影效果,我将按下“恢复”按钮(对不起,我在阴影视图中使用“暂停”按钮制作了图像,实际上它是“恢复”)

【问题讨论】:

    标签: android android-layout animation fade


    【解决方案1】:

    【讨论】:

    • 感谢西蒙,您的快速回复。它起作用了,但它只是把所有东西都涂黑了。我需要黑色阴影.. 以便以前的布局有点可见。
    【解决方案2】:

    hii makki,您可以在 onclick 事件中设置以下代码

        AnimationSet set = new AnimationSet(true);
    
    Animation animation = new AlphaAnimation(0.0f, 1.0f);
    animation.setDuration(50);
    set.addAnimation(animation);
    
    animation = new TranslateAnimation(
    Animation.RELATIVE_TO_SELF, 0.0f,Animation.RELATIVE_TO_SELF, 0.0f,
    Animation.RELATIVE_TO_SELF, -1.0f,Animation.RELATIVE_TO_SELF, 0.0f
    );
    animation.setDuration(100);
    set.addAnimation(animation);
    
    LayoutAnimationController controller = new LayoutAnimationController(set, 0.5f);
    l.setLayoutAnimation(controller);
    

    然后淡出动画

     public static Animation runFadeOutAnimationOn(Activity ctx, View target) {
      Animation animation = AnimationUtils.loadAnimation(ctx,android.R.anim.fade_out);
      target.startAnimation(animation);
      return animation;
    }
    

    【讨论】:

      【解决方案3】:

      以上两个答案都帮助我解决了问题,但两个答案都不是我问题的实际解决方案。我提出的解决方案是

      我根据需要定义了两个动画

      Animation fadeOut = new AlphaAnimation(0f,0.5f);
      Animation fadeIn = new AlphaAnimation(0.5f,1f);
      fadeOut.setFillAfter(true);
      fadeIn.setFillAfter(true);
      

      当我点击“暂停”按钮时,我执行了下一行

      mapLayout.startAnimation(fadeOut);
      

      然后为了从暂停状态恢复,我执行了以下行

      mapLayout.startAnimation(fadeIn);
      

      感谢西蒙和迪帕克!

      【讨论】:

        猜你喜欢
        • 2022-12-15
        • 2012-10-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-03-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多