Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android 9 Patch tool: What is the new layout bounds feature?

I've updated r20 of the Android SDK and started the 9 Patch tool.

There seems to be a new feature - Holding Control and clicking adds layout bounds which are referred to as red pixels.

I've taken a look at the documentation but it seems out of date.

My question is, what are layout bounds used for and what is the best way to use them?

Thanks.

like image 989
Brad Avatar asked Jul 10 '12 04:07

Brad


People also ask

What is layout bounds in Android?

On Android, we have an option called Show layout bounds , which allows us to see bounding areas of your views displayed in vibrant blue and purple. Layout bounds.

What is the 9 patch tool in Android?

The Draw 9-patch tool is a WYSIWYG editor included in Android Studio that allows you to create bitmap images that automatically resize to accommodate the contents of the view and the size of the screen. Selected parts of the image are scaled horizontally or vertically based on indicators drawn within the image.

What is a 9 patch image?

A 9 patch image is a regular png (. PNG) image which is needful for android app developers where they require to wrap any content within a background image without pixelating the background image.


2 Answers

Edit: Supported in Android 4.3 (API level 18). See more recent answer by wayne.

Original: It's not documented because it's not part of the OS yet, only the tools. The red pixels for setting layout bounds are not used by the Android framework (as of Jellybean 4.1.1), so don't set them at this time. You may speculate about what it means to declare where on your image the layout bounds of the control should be. And watch http://android-developers.blogspot.com/ for announcements.

like image 72
Sparky Avatar answered Sep 21 '22 13:09

Sparky


It's for "Optical bounds layout". More details can be found in the Android 4.3 API description. Excerpt:

For views that contain nine-patch background images, you can now specify that they should be aligned with neighboring views based on the "optical" bounds of the background image rather than the "clip" bounds of the view.

For example, figures 1 and 2 each show the same layout, but the version in figure 1 is using clip bounds (the default behavior), while figure 2 is using optical bounds. Because the nine-patch images used for the button and the photo frame include padding around the edges, they don’t appear to align with each other or the text when using clip bounds.

like image 28
Wayne Avatar answered Sep 18 '22 13:09

Wayne