Andy Andy - 1 year ago 71
Android Question

How to properly use the Space class in Android?

I have the need to use some Views as sort of place holders, but to not show anything. Its purpose is to make the

's that do show content to resize and share the available space horizontally. It is not necessary to go into detail, but what I am wondering is if I can use the
class to accomplish this? I have seen it used in a GridLayout blog post, but other than that, there really isn't much on its many possible uses. The doc says its a light implementation of a View, which out of anything, would be the best way to accomplish what I need since it wont be too memory intensive. Is it only intended for GridLayout? There really isn't much info on it online so I was hoping someone could shed some light on the matter.

Just to elaborate a little of why I need to use the
class, I have, say a
. In that LinearLayout could be any number of TextViews horizontally. Say I want to resize it horizontally with a layout gravity, but not actually have another View actually show, just used to simulate that the size of the actually TextView with the content resizes correctly.

I appreciate any help!

Answer Source

The Space class was designed to include empty spaces in general purpose layouts and is very lightweight which makes sure that it doesn't add any overheads. Just put it in your layout like you would any other View. It's not specifically designed for any particular container. You can use it with a LinearLayout, a GridLayout, or anything else. Just don't expect it to display anything (not even a background).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download