【问题标题】:AlphaAnimation Not Working in Ice Cream SandwichAlphaAnimation 在冰淇淋三明治中不起作用
【发布时间】:2012-10-23 10:49:10
【问题描述】:

我通过使用AlphaAnimation 操作其 alpha 级别来显示带有淡入淡出动画的布局。

当前的解决方案在我的两台使用 Gingerbread 的设备和一台使用 Froyo 的设备上运行良好。但是,它不适用于冰淇淋三明治?!

这是我的 xml 布局。

<LinearLayout
        android:id="@+id/photoOptionBar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:alpha="0"
        android:background="@color/gpsBackground"
        android:orientation="horizontal">

        <ImageButton
            android:id="@+id/displayShareBtn"
            style="@android:style/Widget.Holo.Button.Borderless.Small"
            android:background="@android:color/transparent"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical|center_horizontal"
            android:padding="20dp"
            android:src="@drawable/share"
            android:contentDescription="Share the picture"/>

        <ImageButton
            android:id="@+id/displayDiscardBtn"
            style="@android:style/Widget.Holo.Button.Borderless.Small"
            android:background="@android:color/transparent"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical|center_horizontal"
            android:padding="20dp"
            android:src="@drawable/contentdiscard"
            android:contentDescription="Discard Picture"/>

    </LinearLayout>

这是我的 onCreate 方法,用于在加载时将 alpha 设置为 0,因为在 xml 中完成时它不起作用...

    AlphaAnimation alpha = new AlphaAnimation(0.0F, 0.0F);
    alpha.setDuration(0); // Make animation instant
    alpha.setFillAfter(true); // Tell it to persist after the animation ends
    // And then on your layout
    this._photoOptionsBar.startAnimation(alpha);

然后当我想展示它时,我会调用以下内容。

public void showOptions() {
        AlphaAnimation alpha = new AlphaAnimation(0.0F, 1.0F);
        alpha.setDuration(PhotoDisplayFragment.FADE_DURATION); // Make animation instant
        alpha.setFillAfter(true);
        this._photoOptionsBar.startAnimation(alpha);
        this._optionsShowing = true;
}

当我在 IceCream 三明治中加载它时,LinearLayout 就在那里,因为您可以单击按钮并执行它们的功能,并且正在调用要显示的功能但我看不到它!

任何帮助都会很棒

【问题讨论】:

    标签: android android-linearlayout android-4.0-ice-cream-sandwich


    【解决方案1】:

    问题在于线性布局中的android:alpha=0。要使事情正常工作,您必须在布局 xml 中将可见性属性设置为不可见。在开始 alpha 动画之前调用setVisibility(View.VISIBLE)

    【讨论】:

    • 您的问题出在哪里是正确的,但是在 xml 文件中将其设置为 1 使得其余的工作正常。
    • 是的,因为计时器。
    【解决方案2】:

    我也遇到了同样的问题。

    似乎有两个独立的 alpha 属性。 AlphaAnimation 改变一个,android:alpha 改变另一个。这两个属性都在 ICS 上使用,但 android:alpha 在 ICS 之前被忽略。

    因此,如果您设置 android:alpha="0" 并使用 AlphaAnimation 来制作动画,那么在 ICS 之前它会正常工作,因为 android:alpha 会被忽略。在 ICS 上,视图将始终不可见,因为 AlphaAnimation 不会从 0 更改 android:alpha。因此,解决方案就是删除 android:alpha="0" 行。

    我对此不是 100% 确定,但它似乎就是这样。

    我还认为这两个 alpha 的工作方式略有不同。当然,如果您使用半透明图像更改 ImageView 的 alpha,则使用 AlphaAnimation 看起来比使用 android:alpha 更糟糕。但是您对此无能为力。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-02
      • 1970-01-01
      • 2012-03-11
      • 2012-01-09
      • 1970-01-01
      • 2014-03-26
      相关资源
      最近更新 更多