Reputation: 481
I'm a bit stuck again. This time i have an animated button, the animation is fading the button in and out. What i want to achieve is that when i press the button it should disappear. Sounds easy enough, but what I've tried so far doesn't work, and I'm guessing it's because the button is animated.
I've tried setting the button.setVisibility(View.Invisible) in the onClick() listener.. My code is as follows:
Animation: fade.xml
<alpha xmlns:android="http://schemas.android.com/apk/res/android" android:fromAlpha="1.0" android:toAlpha="0.4" android:duration="1000" android:repeatCount="infinite" android:repeatMode="reverse" /> </set>
I have a button declared in my layout xml called buttonStartTest and this is the code in the activity:
Button goButton = (Button) findViewById(R.id.buttonStartTest);
goButton.setVisibility(View.VISIBLE);
goButton.startAnimation(AnimationUtils.loadAnimation(this, R.anim.fade));
goButton.setBackgroundResource(R.drawable.roundedcorners);
goButton.setText("Start");
goButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// click action here
Button goButton = (Button) findViewById(R.id.buttonStartTest);
goButton.setVisibility(View.INVISIBLE);
}
});
The problem is that the button doesn't disappear.. I can alter it in other ways in the onClick() though.. So my fellow coders, how do I go about hiding the button?
much love, Daniel
Upvotes: 0
Views: 2762
Reputation: 5119
Looking your anim file, it's infinite, so the alpha value from your button will vary to 1-0.4 so you must first stop your animation:
goButton.clearAnimation();
Then you can hide your button:
goButton.setVisibility(View.INVISIBLE)
Upvotes: 2
Reputation: 1215
You should do a
goButton.clearAnimation()
inside your on click listener, so that when you click on it, you will stop the animation, and then you can use
goButton.setVisibility(View.Gone)
to fully hide it once and for all.
Upvotes: 2
Reputation: 3236
Try this for me, if it works (which I think it will), then i'll explain.
goButton.setVisibility(View.GONE);
The reason I believe is because setting it to invisible only makes the button transparent. Your animation will override that.
I haven't had a chance to test this solution myself since I am not on my home PC, but this should work - Please let me know.
Upvotes: 1