Recent Changes‎ > ‎

Resize Support

posted Jun 15, 2011, 8:44 AM by Tor Norbye
The layout editor now supports resizing. Let's say you have the following layout:

Clicking on a view now shows the following selection rectangle, instead of the blue tint we've used up until now:
When you move the cursor over any of the corners, the cursor will switch to a resize cursor, and you can drag each corner to resize the view:
Here we're resizing the image. Notice the smaller green rectangle inside the resize bounds. This is showing you the "preferred" (or wrap_content) size of the view, and if you move the cursor near it, then the bounds will snap to that resize value.  Similarly, the green lines on the right and bottom are showing you the match_parent size, and the cursor will snap to these if you get near as well.

For any other sizes, the size will be set to the corresponding "dip" (device independent pixel) size, and the current size is shown in the Eclipse status area:
Using a pixel size (or wrap_content or match_parent) for the size is the default behavior for all layouts. However, some layouts override this default to provide a more useful behavior.

For example, in a RelativeLayout, resizing along any edge will instead attach that edge to some other view or parent rather than assign a size (more on the new RelativeLayout support in a separate post.)

As another example, in a LinearLayout, the layout editor will compute layout weights instead and use those instead of pixel widths. If you for example resize your widget to be about 65% of the view, here's the feedback in the status area:
And finally, speaking of LinearLayout weights - the LinearLayout support now has two additional weight-related actions in the layout actions bar:
There is a new action to assign all weight to the current selected widget(s); this will remove all weights from other widgets, and assign all the weight to the selection along with setting their size to 0dp to ensure that they will take an equal proportion of the size regardless of their intrinsic size. The other action just clears the weights and converts any 0dp sizes back to wrap_content. Note that whereas the new resize support is in ADT 12, the layout actions were added after the branch so they will not appear in the next milestone build.