I struggled with this for a few hours then gave up on it. Apparently
people have been asking this question for several years without a
meaningful solution. I ended up using the much-maligned nested linear
layouts approach instead.
Anyway, the issue wasn't related to height, but width. I'm fine with the
grid view scrolling vertically, but when I specify that it has only 3
columns, I want to be able to center those three in its parent,
otherwise it looks awful. Seems like there's no good way to do that.
Next, I don't want to give it fixed dimensions because the range of
devices causes the stuff I put inside it to grow and shrink with screen
sizes. As far as I'm aware, there's no way to specify a percentage in
either dimension.
Anyway, the problem is solved for the moment, although I'm not terribly
excited about how I had to do it.
On 12/5/2011 7:47 AM, Mark Murphy wrote:
I would assume that GridView does not support wrap_content for
android:layout_height, no different that ListView. I'm not sure it
supports wrap_content for android:layout_width, either. And, of
course, your RelativeLayout doesn't have the attribute in your post
title, though I assume that's a copy/paste issue. :-)
Try it with a GridView with fixed dimensions and see what happens.
On Sun, Dec 4, 2011 at 5:41 PM, Christopher Van Kirk
<christopher.vank...@gmail.com> wrote:
I've tried several times now to use android:layout_alignCenterInParent to
center a child in its parent RelativeLayout view, but it never seems to
work.
What's wrong with this code, and why doesn't it center the GridView in the
outer RelativeView?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
<GridView
android:id="@+id/select_grid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:numColumns="3"
android:columnWidth="90dp"
android:stretchMode="none"
android:gravity="center"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp">
</GridView>
</RelativeLayout>
--
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