Friday, September 2, 2011

Re: [android-developers] GridView shows only one row with layout_height=WRAP_CONTENT

On Fri, Sep 2, 2011 at 7:33 PM, Shri <shri.borde@gmail.com> wrote:
> I am using a GridView in a LinearLayout. I want the GridView to show
> up as tall as needed to show all the rows.

That is not really possible. For example, if you have a million cells,
the user's device is not going to stretch to a few hundred meters just
to please you.

> However, I am seeing only
> one row when set (layout_width=MATCH_PARENT and)
> layout_height=WRAP_CONTENT.

wrap_content is not a valid value for vertically scrollable widgets,
particularly ListView and GridView. Please use
fill_parent/match_parent, optionally along with other layout rules to
control the size (e.g., layout_weight for LinearLayout).

> Looking at onMeasure in http://www.netmite.com/android/mydroid/frameworks/base/core/java/android/widget/GridView.java,

That is not a valid source URL for current versions of Android AFAIK.
Use Google Code Search or http://source.android.com, though the latter
may still be down due to the kernel.org hack from earlier in the week.

> I see that onMeasure does not calculate the number of rows at all, and
> so I can understand why only one row shows up. So it seems like an
> oversight.

No, it seems like it works as expected.

> Shouldn't layout_height=WRAP_CONTENT show all rows (if possible)?

No.

> Is there any workaround?

No. Please use fill_parent/match_parent, optionally along with other
layout rules to control the size (e.g., layout_weight for
LinearLayout).

--
Mark Murphy (a Commons Guy)
http://commonsware.com | http://github.com/commonsguy
http://commonsware.com/blog | http://twitter.com/commonsguy

Android 3.1 Programming Books: http://commonsware.com/books

--
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+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment