I have a LinearLayout which I create in my xml file with its visibility set to Gone. I then showIt using an Animation and thats fine.
I fade out my LinearLayout using an AlphaAnimation and this works fine.
My Problem
The problem however is when I listen to the animation using an AnimationListener and the onAnimationEnd method is called, it doesn’t set the visibility of my LinearLayout to GONE as I can still click the ImageButtons that are inside it which is how I know they’re still there.
here is my xml with my LinearLayout.
<LinearLayout
android:id="@+id/photoOptionBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:alpha="1"
android:background="@color/gpsBackground"
android:orientation="horizontal"
android:visibility="gone">
<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 fade out method along with the listener.
AlphaAnimation alpha = new AlphaAnimation(1.0F, 0.0F);
alpha.setDuration(PhotoDisplayFragment.FADE_DURATION); // Make animation instant
alpha.setFillAfter(true); // Tell it to persist after the animation ends
// And then on your layout
final LinearLayout temp = this._photoOptionsBar;
alpha.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
temp.setVisibility(View.GONE);
}
@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
});
this._photoOptionsBar.startAnimation(alpha);
My Question
How do I set the visibility of the my LinearLayout to GONE after the animation ends?
Thanks in advance
The issue is related to
setFillAfterwhich let the animation persist when it is finished. Remove and all will work as expected. If if you need the fade in animatio check the_photoOptionsBarvisibilty and if it is gone apply the inverse animation: