4

According to the accepted answer to this question GridView row height, if you...

"Set your LinearLayouts to be some specific height, and the rows will all be that height."

This does not appear to work in my case. I have a layout file for each row as so:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" 
    android:layout_width="wrap_content"
    android:layout_height="200dp"
    android:layout_gravity="center_horizontal">

    <ImageView 
        android:id="@+id/theimage"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_gravity="center_horizontal"
        android:background="#ffff0000" />

    <TextView 
        android:id="@+id/thename"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:layout_gravity="center_horizontal"
        android:gravity="center"
        style="?icontext" 
        android:background="#ff00ff00"/>

</LinearLayout>

And these are contained within a Gridview defined as so:

<GridView android:id="@+id/gridview" 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" 
        android:numColumns="auto_fit" 
        android:columnWidth="100dp"
        android:background="@color/background" 
        android:verticalSpacing="1dp"
        android:horizontalSpacing="5dp" />

This ignores the 'android:layout_height="200dp"' and instead sets the row height to the cell's content.

What's worse is that when my TextView wraps onto a second line, that second line is obscured by the next row of cells.

What am I missing?

Community
  • 1
  • 1
Chris Simpson
  • 7,821
  • 10
  • 48
  • 68
  • Maybe you should check this question and it's answer: [Layout problem with button margin](http://stackoverflow.com/questions/5315529/layout-problem-with-button-margin) – Dominik Mohr Aug 25 '11 at 23:14
  • Ahh, yes, that makes sense. Maybe you should post this as an answer? – Chris Simpson Aug 25 '11 at 23:36

1 Answers1

9

The problem is solved in the following question: Layout problem with button margin

android:layout_* attributes are LayoutParams and belong to the parent view. So they will be ignored if you don't specify any parent.

Community
  • 1
  • 1
Dominik Mohr
  • 827
  • 9
  • 19
  • Thank you! I had a fragment that contained just a TextView, but that view's height was being ignored. Putting a FrameLayout around the view in the fragment fixed that issue. – Jack O'Connor Oct 28 '13 at 22:40