[android-developers] Layout problem: equal margins in XML
I have a rather involved requirement for a rather simple layout. I have an activity with a single ListView floating in the middle of the screen with a background margin of uniform width all around. So far no problem. Now I need the margin to be as large as possible given the content of the ListView, but always equal all around. Furthermore, if the ListView contents are higher than the screen, then there needs to be a minimum margin (that is, the margin cannot shrink to zero). Another way of stating the problem: the ListView should be nominally sized to wrap_content, except it should then expand in x or y as necessary to equalize the margins. Without the equal-all-around requirement, or without the margin-as-large-as-possible requirement, this would all be fairly simple to do using layout_weight. Is there a way to implement both requirements? (In XML with stock UI elements, that is; I know I could do this in code.) -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] Layout problem: equal margins in XML
What if the list view's content produces unequal margins in the horizontal and vertical directions? I don't think your requirement, as written, can handle this. If equal horizontal and vertical margins weren't a requirement, I'd say make a FrameLayout with minimum margins (or padding), then set your list view to wrap_content / wrap_content, and layout_gravity to "center". That should come pretty close. Other than that, you might need to write your own ViewGroup subclass, perhaps starting by subclassing FrameLayout. -- Kostya 2011/6/12 Ted Hopp > I have a rather involved requirement for a rather simple layout. I have an > activity with a single ListView floating in the middle of the screen with a > background margin of uniform width all around. So far no problem. Now I need > the margin to be as large as possible given the content of the ListView, but > always equal all around. Furthermore, if the ListView contents are higher > than the screen, then there needs to be a minimum margin (that is, the > margin cannot shrink to zero). Another way of stating the problem: the > ListView should be nominally sized to wrap_content, except it should then > expand in x or y as necessary to equalize the margins. > > Without the equal-all-around requirement, or without the > margin-as-large-as-possible requirement, this would all be fairly simple to > do using layout_weight. Is there a way to implement both requirements? (In > XML with stock UI elements, that is; I know I could do this in code.) > > -- > You received this message because you are subscribed to the Google > Groups "Android Developers" group. > To post to this group, send email to android-developers@googlegroups.com > To unsubscribe from this group, send email to > android-developers+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] Layout problem: equal margins in XML
I thought I had addressed that. Assuming that the smaller margins are at least the minimum, then the larger margins should shrink (the ListView should expand in that dimension) until they are equal all around. I think you are right that this cannot be done in XML alone, but I asked hoping that I'm wrong. -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] Layout problem: equal margins in XML
On Sun, Jun 12, 2011 at 10:23 PM, Ted Hopp wrote: > I thought I had addressed that. Assuming that the smaller margins are at > least the minimum, then the larger margins should shrink (the ListView > should expand in that dimension) until they are equal all around. I think > you are right that this cannot be done in XML alone, but I asked hoping that > I'm wrong. Well, if you create and open source a custom layout manager that does all that, then the rest of us can do it in XML alone... :-) -- Mark Murphy (a Commons Guy) http://commonsware.com | http://github.com/commonsguy http://commonsware.com/blog | http://twitter.com/commonsguy Warescription: Three Android Books, Plus Updates, One Low Price! -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en