I am creating a UI on an android application. When I invoke the view.startAnimation(anim). It work fades the button away as desired but as soon as the animation has concluded in interpolating the alpha from 1 -> 0, it reappears. I assume the alpha reset to its original value. I am not sure what I missed.
I am using the latest android api, and testing on a galaxy s9 physical device.
I have investigate the following pages to try solve my issue, one a youtube tutorial the other a stack Overflow answered question. https://www.youtube.com/watch?v=x6QS6m1pYMs Fade In Fade Out Android Animation in Java
I have set everything up as follows, xmls:
<ToggleButton
android:id="@+id/my_button_toggle"
android:layout_width="100dp"
android:layout_height="50dp"
android:layout_gravity="bottom|right"
android:gravity="center" />
<Button
android:id="@+id/my_button"
android:textSize="12dp"
android:layout_width="100dp"
android:layout_height="50dp"
android:layout_gravity="bottom|center"/>
The above is define inside a FrameLayout with a fragment defined before it.
set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
android:id="@+id/fade_out"
android:duration="500"
android:fromAlpha="1.0" android:toAlpha="0.0"
android:interpolator="@android:anim/accelerate_interpolator"
android:fillAfter="true" />
</set>
with the calling Java put together like this..
//global
ToggleButton togglebutton;
Button button;
void hideUI(){
fade(togglebutton);
fade(button);
}
void fade(View view){
Button fadingButton = (Button) view;
Animation fadeOutAnimation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.fade_out);
fadingButton.startAnimation(fadeOutAnimation);
}