Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AlphaAnimation Not Working in Ice Cream Sandwich

I am display a layout with fade animation by manipulating its alpha levels using AlphaAnimation.

The current solution works fine on two of my devices which use Gingerbread and one which uses Froyo. However, it does not work on Ice Cream Sandwich?!

Here is my xml layout.

<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>

Here is my onCreate method to set the alpha to 0 on loadup as when done in xml it doesn't work...

    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);

And then when I want to show it I call the following.

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;
}

When I load it up in IceCream sandwich the LinearLayout is there because you can click the buttons and it executes their function, and the functions to show are being called but I just can't see it!

Any help would be great

like image 542
StuStirling Avatar asked Feb 18 '23 18:02

StuStirling


1 Answers

The problem is with android:alpha=0 in the Linear Layout. To make things work you have to set visibility property to invisible in layout xml. And before starting alpha animation call setVisibility(View.VISIBLE)

like image 129
Avadhani Y Avatar answered Feb 28 '23 01:02

Avadhani Y