1

In my application, I have a layout which includes a LinearLayout--> Top, GridView--> Middle and a set of views which should be aligned to the bottom.

1. Layout when gridview is not having much content

2. Layout when grid view contents are increased

3. Layout as how it should be shown when Gridview content is very large

<code>**Layout when gridview is not having much content**</code> Layout when grid view contents are increased Layout as how it should be shown when Gridview content is very large

Presently my gridview is expanding when the contents in it is increasing that the lower level contents are not visible in the screen.

I don't want to assign specific height to the grid view as it is looking weird in screens with different dimensions.

Is there any way that the gridview expands only upto the bottom views? My parent layout is LinearLayout. I have tried out with relative layout, but it is not working.

Aswathy P Krishnan
  • 11,728
  • 7
  • 27
  • 45

1 Answers1

2

I too faced the same problem and found the solution by modifying the respective xmls as below:

  1. Use RelativeLayout as Parent Layout.
  2. Place the Header Content in RelativeLayout
  3. Use ScrollView for the GridView which changes dynamically.
  4. Place the Footer Layout after ScrollView

as shown below:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent" >
 <TextView
    android:id="@+id/txtTextView"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"/>
  <ScrollView
    android:id="@+id/scro1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_below="@id/txtTextView" >
  <LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
  <GridView
    android:id="@+id/scro1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"/>
  </LinearLayout>
  </ScrollView>
  </RelativeLayout>

android:layout_below attribute in ScrollView makes the difference.

Avadhani Y
  • 7,566
  • 19
  • 63
  • 90
  • 1
    `GridView` would have its own scroll, so its pointless to have `GridView` inside a scroll. – Adil Soomro Dec 20 '12 at 07:36
  • I tried using the `gridview inside a scrollview`, but didn't work. :( – Aswathy P Krishnan Dec 20 '12 at 07:41
  • Did you try it with a footer layout? When I am trying it, I have my scrollview extended up to the bottom of the screen that the footer layout is not at all visible. – Aswathy P Krishnan Dec 20 '12 at 08:26
  • In my case, it is working fine when there are less contents in the gridview, but when it starts increasing, the lower views starts moving downing making it disappear from the layout at last. As those views are not bound in a scroll view, they are not visible again – Aswathy P Krishnan Dec 20 '12 at 11:31
  • Ok i have to search for that actually... finally do u find the solution from my answer....?? – Avadhani Y Dec 20 '12 at 11:39
  • I am afraid, I it was not working in my case. So I tried to code the gridview's height programmatically according to the items count inside the gridview. Even that didn't work. This is the [link](http://stackoverflow.com/questions/13974289/how-to-set-height-of-gridview-programmatically-android) to that question. – Aswathy P Krishnan Dec 26 '12 at 04:58