Android Layout Tricks #1 problem

65 views
Skip to first unread message

Spencer Riddering

unread,
Feb 26, 2009, 10:31:15 AM2/26/09
to Android Developers
Concerning Romain Guy's post titled "Android Layout Tricks #1" in the
Android Developers Blog.

I just tried to put it to use on a list item (as the article suggests
its good for) and it doesn't work for me. Was this code actually
tested in a list item?

I believe I ran into the same problem last September
http://groups.google.com/group/android-developers/browse_frm/thread/764ea3532ff7c4e0
but I never found an explanation.

So, I'm asking a second time;

Why can't I center things vertically within a RelativeLayout that
is in a list item?


Spencer Riddering

Marco Nelissen

unread,
Feb 26, 2009, 12:34:20 PM2/26/09
to android-d...@googlegroups.com
On Thu, Feb 26, 2009 at 7:31 AM, Spencer Riddering
<ponder...@gmail.com> wrote:
>
> Concerning Romain Guy's post titled "Android Layout Tricks #1" in the
> Android Developers Blog.
>
> I just tried to put it to use on a list item (as the article suggests
> its good for) and it doesn't work for me. Was this code actually
> tested in a list item?

Are you saying you copy/pasted the xml layout from the blog post
verbatim, and it didn't behave as described in the blog post?

> I believe I ran into the same problem last September
>    http://groups.google.com/group/android-developers/browse_frm/thread/764ea3532ff7c4e0
> but I never found an explanation.
>
> So, I'm asking a second time;
>
>    Why can't I center things vertically within a RelativeLayout that
> is in a list item?

Because you're doing it wrong? ;)
Seriously though, there are multiple apps that center things
vertically in a RelativeLayout in a list item, so it certainly is
possible.

Romain Guy

unread,
Feb 26, 2009, 1:18:23 PM2/26/09
to android-d...@googlegroups.com
When you load a list item make sure you use the inflate() method with
the following parameters:

inflate(layoutId, parent, false)

Not passing the parent will cause ListView to choose the layout
parameters it wants.
--
Romain Guy
Android framework engineer
roma...@android.com

Note: please don't send private questions to me, as I don't have time
to provide private support. All such questions should be posted on
public forums, where I and others can see and answer them

Spencer Riddering

unread,
Feb 26, 2009, 10:15:30 PM2/26/09
to Android Developers
Oh, my bad. I just noticed one difference. I copy/pasted the contents
of the RelativeLayout but not the RelativeLayout itself :) Apparently

android:layout_height="wrap_content"

isn't a good choice in this case. The RelativeLayout's height must be
a fixed height like:

android:layout_height="?android:attr/listPreferredItemHeight"
or
android:layout_height="100dip"

I just noticed the documentation for RelativeLayout even warns against
attempting to create a "... circular dependency between the size of
the RelativeLayout and the position of its children."

Spencer

On Feb 27, 2:18 am, Romain Guy <romain...@google.com> wrote:
> When you load a list item make sure you use the inflate() method with
> the following parameters:
>
> inflate(layoutId, parent, false)
>
> Not passing the parent will cause ListView to choose the layout
> parameters it wants.
>
>
>
> On Thu, Feb 26, 2009 at 9:34 AM, Marco Nelissen <marc...@android.com> wrote:
>
> > On Thu, Feb 26, 2009 at 7:31 AM, Spencer Riddering
> > <ponderyon...@gmail.com> wrote:
>
> >> Concerning Romain Guy's post titled "Android Layout Tricks #1" in the
> >> Android Developers Blog.
>
> >> I just tried to put it to use on a list item (as the article suggests
> >> its good for) and it doesn't work for me. Was this code actually
> >> tested in a list item?
>
> > Are you saying you copy/pasted the xml layout from the blog post
> > verbatim, and it didn't behave as described in the blog post?
>
> >> I believe I ran into the same problem last September
> >>    http://groups.google.com/group/android-developers/browse_frm/thread/7...
> >> but I never found an explanation.
>
> >> So, I'm asking a second time;
>
> >>    Why can't I center things vertically within a RelativeLayout that
> >> is in a list item?
>
> > Because you're doing it wrong? ;)
> > Seriously though, there are multiple apps that center things
> > vertically in a RelativeLayout in a list item, so it certainly is
> > possible.
>
> --
> Romain Guy
> Android framework engineer
> romain...@android.com
Reply all
Reply to author
Forward
0 new messages