I would like to know if there is a simple way to add a view (a button) to a RelativeLayout, with some kind of scale animation.
I extended a class from Button and did something like this:
public class MyButton extends Button {
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
ScaleAnimation anim = new ScaleAnimation(0,1,0,1);
anim.setDuration(1000);
anim.setFillAfter(true);
this.startAnimation(anim);
}
Then tried to add this button to a view and it didn’t work. Please help!
I tested your animated button implementation and it works correctly. There must be some other problem. Probably the way you add the button to the layout.
To add your button to the relative layout use code like this.
Or you can inflate the button from layout. To do this create layout
mybtn.xmlcontaining your button implementation:To add it to your layout call:
There might be a problem with proper positioning of your view when you add it to the relative layout. Just add code like this before calling
rl.addView(b1)(the code snippet adds new button below someOtherView).