Actually, I am using a GridView in a ListView, not a LinearLayout. So the
entire grid can actually be displayed by scrolling the list (with the
Adapter architecture kicking in to display only those cells of the grid that
are visible on screen). I am using the GridView as a table, and it seems
reasonable to want to display the table in a ListView. There needs to be
some way to accomplish this.
One workaround I found was to override #onMeasure. This does show all the
rows of the GridView (on Gingerbread and Honeycomb)
public class MyGridView extends GridView {
public MyGridView(Context context, AttributeSet attrs) {
super(context, attrs);
}
protected void onMeasure (int widthMeasureSpec, int heightMeasureSpec) {
heightMeasureSpec = MeasureSpec.makeMeasureSpec(
MeasureSpec.AT_MOST, MAX_EXPECTED_HEIGHT_OF_TABLE);
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}
On Fri, Sep 2, 2011 at 4:42 PM, Mark Murphy <[email protected]> wrote:
> On Fri, Sep 2, 2011 at 7:33 PM, Shri <[email protected]> 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 [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> 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 [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en