【问题标题】:Android - removing shadow on pressed animationAndroid - 消除按下动画上的阴影
【发布时间】:2015-12-08 23:47:40
【问题描述】:

我有一个 FAB,当两个动作之一发生时,我想通过翻转来制作动画。第一个是屏幕内容的变化,第二个是按下FAB确认动作。

我正在使用支持库 v22.2.1 中的 FAB

我正在使用这个对象动画师来做它

 ObjectAnimator animation = ObjectAnimator.ofFloat(myFab, "rotationY", 0.0f, 360f);
                animation.setDuration(400);
                animation.setInterpolator(new AccelerateDecelerateInterpolator());
                animation.start();

动画按预期工作,视图翻转并且在每个棒棒糖设备上看起来很完美。

在 Lollipop 设备上,它还会翻转阴影,这看起来真的很糟糕而且会分散注意力。

我将 FAB 设置为 6 高程

   <android.support.design.widget.FloatingActionButton
    android:id="@+id/my_fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_alignParentBottom="true"
    android:layout_margin="@dimen/fab_compat_margin"    
    app:borderWidth="0dp"
    app:elevation="6dp"/>

为了解决这个问题,我在动画开始之前将高度设置为 0,并在 onAnimationEnd 中将其设置回 6。

当触发动画的动作不是按下的工厂时,此方法有效。

当我按下FAB时,它仍然显示阴影,并且是一个更大的阴影。看起来按下状态阴影与高度阴影是分开的。

我尝试设置一个触摸监听器并移除那里的阴影,但由于触摸,阴影已经存在。

关于如何绕过触摸阴影动画的任何想法?

【问题讨论】:

    标签: android android-animation material-design android-design-library androiddesignsupport


    【解决方案1】:

    我想通了。

    如果我将 StateListAnimatior 设置为 null,则按下的阴影消失并且动画可以正常工作。

    myFab.setStateListAnimator(null);

    这个阴影与高程阴影是分开的,所以我仍然需要在开始动画之前将它们设置为 0。

    【讨论】:

      【解决方案2】:

      现在您可以在使用Material FAB时直接设置translationZ

      app:pressedTranslationZ="0dp"
      app:hoveredFocusedTranslationZ="0dp"
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-04-28
        • 2022-01-21
        • 2015-10-11
        • 2015-03-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-04-29
        相关资源
        最近更新 更多