【问题标题】:Applying animation with alpha=0 makes background white instead black使用 alpha=0 应用动画会使背景变为白色而不是黑色
【发布时间】:2014-03-28 09:18:05
【问题描述】:

我正在尝试应用 淡入淡出效果 以使所有屏幕变暗,就像提示对话框组件时一样,但我的屏幕在动画时变成白色而不是黑色。我将动画应用于作为所有视图的父级的 LinearLayout。动画代码如下:

<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator"
android:fromAlpha="1.0" android:toAlpha="0.25" android:duration="500" android:fillAfter="true"/>

以及执行:

relcontrol.startAnimation(AnimationUtils.loadAnimation(this, R.anim.foregroundanim));

它对白色产生淡入淡出效果....为什么?

【问题讨论】:

  • 你提到了你的动画根视图,对吧?只需将其再次包装在另一个 viewGroup 中,然后为其设置动画
  • 可能是因为你的主题很轻??
  • 是的,我的主题是:@style/Theme.Sherlock.Light.NoActionBar ...但我认为如果我想要 NoActionBar 则无事可做导致层次结构

标签: android animation fade alpha animationutils


【解决方案1】:

是的!我已经包裹到另一个黑色背景的视图中,现在它可以工作了:

<RelativeLayout
    android:id="@+id/my_newparent"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    xmlns:tools="http://schemas.android.com/tools"
    android:background="#000">
    <LinearLayout
          android:id="@+id/my_oldparent"
          android:orientation="vertical"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:background="@drawable/generalbackground">
...
...

非常感谢两位!!

【讨论】:

    【解决方案2】:

    参考Here

    android:fromAlpha
    

    浮动。起始不透明度偏移,其中 0.0 为透明,1.0 为不透明。

    android:toAlpha
    

    浮动。结束不透明度偏移,其中 0.0 为透明,1.0 为不透明。

    根据您的要求更改值。你可以得到它。

    谢谢

    【讨论】:

      猜你喜欢
      • 2021-04-28
      • 1970-01-01
      • 2013-07-31
      • 2018-10-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-13
      相关资源
      最近更新 更多