Reputation: 199
I have an Image view, i am applying animation to it, it has to move up and down on the screen when the button is pressed. But before the button is pressed i want the image hidden.
I am using the following code:
final Animation animation = AnimationUtils.loadAnimation(this,
R.anim.aim);
animation.reset();
maxName.startAnimation(animation);
anim.xml
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="4000"
android:fromYDelta="15%p"
android:repeatCount="2"
android:repeatMode="reverse"
android:toYDelta="60%p" />
What changes should i make in order to hide the image before the button is pressed.
Thank-you in advance.
Upvotes: 1
Views: 559
Reputation: 5629
Try to add
android:visibility="invisible"
to your element in its xml file? You can also use gone
instead of invisible
if you want the element to occupy no space in your layout.
Then when the button is pressed, you can change the visibility of the element at runtime:
final Animation animation = AnimationUtils.loadAnimation(this,
R.anim.aim);
animation.reset();
maxName.setVisibility(View.VISIBLE);
maxName.startAnimation(animation);
Upvotes: 1
Reputation: 352
Add AnimationListener to your animation .. and write down
yourImageview.setvisibility(view.gone) in onAnimationStart
yourImageview.setvisibility(view.visible) in onAnimationEnd
Upvotes: 1