-->

Expanding button to x,y positions

2019-08-23 02:40发布

问题:

Here are my two buttons: http://prntscr.com/hos2hz (Ignore the dotted line)

I want the GREEN button to expand with an animation to fill the whole of the view (highlighted in red): http://prntscr.com/hos3hm

If the answer could be programmatically, rather than XML, that would be fantastic.

I would imagine it would be something to do with expanding to its parent view, or more likely to an X,Y,Width,Height position, but I'm not quite sure.

All help is greatly appreciated :)

回答1:

You can do something like this

TransitionManager.beginDelayedTransition(parent);

RelativeLayout.LayoutParams parms = (RelativeLayout.LayoutParams) child.getLayoutParams();
parms.height = RelativeLayout.LayoutParams.MATCH_PARENT;
parms.width = RelativeLayout.LayoutParams.MATCH_PARENT;

child.setLayoutParams(parms);