1

Problem image: https://i.stack.imgur.com/0AUL9.png

I have a grid view, that has my HomeViewShortcutItemViews.

In my HomeViewShortcutItemView onMeasure, I'm making it square:

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec){
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    int width = getMeasuredWidth();
    setMeasuredDimension(width, width); /* make grid item square */
}

And in my this view's xml, I'm setting height to match_parent:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/wrapper"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/blue"
    >
...
</RelativeLayout>

But it's rendering it's wrap_content height in grid view item, because onMeasure do not effect it's child view, but making it square as I want.

How can I achive what I want?

By the way, here is the GridView Xml:

<pe.kor.browser.Ui.TabView.HomeView.StaticGridView
      android:id="@+id/gridViewShortcuts"
      android:gravity="center"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:drawSelectorOnTop="false"
      android:listSelector="@drawable/view_home_shortcut_item_bg"
      android:stretchMode="columnWidth"
      android:verticalSpacing="4dp"
      android:horizontalSpacing="4dp"
 />
Lazy
  • 1,807
  • 4
  • 29
  • 49

1 Answers1

0

Change the height in the grid view to match-parent and it will fill your wrapper. As it stands it is set to wrap content.

Have a look at these questions:

Making GridView items square
How to force GridView to generate square cells in Android

Community
  • 1
  • 1
  • When I try match_parent on GridView, problem is still same. But first link you provided solved. Thanks. – Lazy Sep 09 '15 at 22:57