I am trying to set animation for a relative layout in one of my activity_main.xml layout. I want the relative layout to slide upward when visibility is set to visible, and slide downward when visibility is set to gone/invisible. But I was only able to get the animation to slide upward and slide downward once. When I clicked the button again to have the layout slide upward again (and set to visible), the layout just popped out without animation; and as well as when I clicked the button again to have it slide downward (and set to gone/invisible), the layout also just disappears without animation. I would really appreciate your help. Thank you very much!
Here is what I have tried:
Private RelativeLayout relLayoutInfo = findViewById(R.id.rel_Layout_Info);
Private Button btnSlideUp = findViewById(R.id.btn_Up);
Private Button brnSlideDown = findViewById(R.id.btn_Down);
private Animation extraInfoAnimationEnter = AnimationUtils.loadAnimation(getApplicationContext(),R.anim.details_info_animation_enter);
Private extraInfoAnimationExit = AnimationUtils.loadAnimation(getApplicationContext(),R.anim.details_info_animation_exit);
btnSlideUp.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                relLayoutInfo.setAnimation(extraInfoAnimationEnter);
                relLayoutInfo.setVisibility(View.VISIBLE);
            }
        });
btnSlideDown.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                relLayoutInfo.setAnimation(extraInfoAnimationExit);
                relLayoutInfo.setVisibility(View.GONE);
            }
        });
This is the animation file for extraInfoAnimationEnter:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate
        android:fromYDelta="100%"
        android:toYDelta="0"
        android:duration="500">
    </translate>
</set>
This is the animation file for extraInfoAnimationExit:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate
        android:fromYDelta="0"
        android:toYDelta="100%"
        android:duration="500">
    </translate>
</set>
 
     
    