AlphaAnimation does not work in an ice cream sandwich

I show a layout with fade animation by manipulating its alpha levels with AlphaAnimation .

The current solution works fine on two of my devices that use Gingerbread, and one that uses Froyo. However, this does not work on an 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 value to 0 at boot, as it is done in xml, this does not 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 into an IceCream sandwich, LinearLayout exists because you can click the buttons and it performs their function, and the functions to display are called, but I just can't see them!

Any help would be great

+4
source share
2 answers

The problem is android:alpha=0 in linear layout. For everything to be in order, you must set the visibility property to invisible in the xml layout. And before starting the alpha animation call setVisibility(View.VISIBLE)

+6
source

I had the same problem.

There seem to be two separate alpha properties. AlphaAnimation changes one, and android:alpha changes the other. Both properties are used in ICS, but android:alpha ignored by pre-ICS.

So, if you set android:alpha="0" and use AlphaAnimation for animation, pre-ICS will work fine, since android:alpha ignored. In ICS, the view will always be invisible because AlphaAnimation does not change android:alpha to 0. Therefore, the solution simply removes the line android:alpha="0" .

I am not 100% sure of this, but it is similar to how he behaves.

I also think that two alpha works a little differently. Of course, if you change the alpha of ImageView with a translucent image, it looks much worse with AlphaAnimation than android:alpha . But you can’t do anything about it.

+2
source

Source: https://habr.com/ru/post/1441523/


All Articles