views:

1525

answers:

4

Hi, I've got an activity that displays 5 GridViews. Each of these GridViews is divided by a text view with a background that spans the width of the screen. The GridViews represent a volume of books, and each item in the grid is a button representing a book in a volume. All the GridViews and TextViews sit inside a RelativeLayout. Some Volumes have many books and others just a few, so I've been trying to get the individual grid views to wrap_content and take up all the space they need to show all of their books, but no luck. The View equally divides space to each of the GridViews, hiding most of the books. I have my xml layout below. Can anyone tell me how I can get this done? I've tried dozens of approaches, all of which yeild the same results. thank you.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:as="http://schemas.android.com/apk/res/edu.byu.scriptures"  
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <RelativeLayout android:id="@+id/gridNavBar"
        android:layout_height="44px"
        android:layout_width="fill_parent"
        android:background="@drawable/bgnd_1_44"
        android:paddingBottom="0px">
        <Button
         android:id="@+id/homeButton"
         android:layout_height="wrap_content"
         android:layout_width="wrap_content"
         android:layout_alignParentLeft="true"
         android:layout_centerVertical="true"
         android:layout_marginLeft="5px"
         android:text="Home"
                android:textSize="14sp"
                android:textColor="#fff"
                android:shadowColor="#444"
                android:shadowRadius="1"
                android:shadowDx="1"
                android:shadowDy="-1"
             android:background="@drawable/generic_button_xml"/>
    <TextView android:id="@+id/bookRef"
     android:text="Books"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_centerHorizontal="true"
     android:layout_centerVertical="true"
     android:textColor="#fff"
     android:textSize="18sp"
     android:textStyle="bold"
        android:shadowColor="#444"
        android:shadowRadius="1"
        android:shadowDx="1"
        android:shadowDy="-1"
     />
</RelativeLayout>
<ScrollView
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 android:layout_below="@id/gridNavBar">
 <RelativeLayout
  android:orientation="vertical"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"> 
      <TextView
       android:gravity="top"
       android:id="@+id/vol1DividerBar"
       android:layout_width="fill_parent"
       android:layout_height="wrap_content"
       android:text="Volume 1"
       android:textColor="#000"
       android:background="@drawable/volume_divider"
       android:layout_centerHorizontal="true"
       android:layout_alignParentTop="true"/>
      <GridView 
       android:layout_weight="1"
       android:id="@+id/vol1Grid"
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent"
       android:numColumns="auto_fit"
       android:verticalSpacing="0dp"
       android:horizontalSpacing="0dp"
       android:layout_below="@id/vol1DividerBar"/>
      <TextView
       android:layout_weight="1"
       android:id="@+id/vol2DividerBar"
       android:layout_width="fill_parent"
       android:layout_height="wrap_content"
    android:text="Volume 2"
    android:textColor="#000"
    android:background="@drawable/volume_divider"
    android:layout_below="@id/vol1Grid"/>
      <GridView
       android:layout_weight="1"
       android:id="@+id/vol2Grid"
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content"
       android:numColumns="auto_fit"
       android:verticalSpacing="0dp"
       android:horizontalSpacing="0dp"
       android:layout_below="@id/vol2DividerBar"/>
      <TextView
       android:layout_weight="1"
       android:id="@+id/vol3DividerBar"
       android:layout_width="fill_parent"
       android:layout_height="wrap_content"
    android:text="Volume 3"
    android:textColor="#000"
    android:background="@drawable/volume_divider"
    android:layout_below="@id/vol2Grid"/>
      <GridView
       android:layout_weight="1" 
       android:id="@+id/vol3Grid"
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content"
       android:numColumns="auto_fit"
       android:verticalSpacing="0dp"
       android:horizontalSpacing="0dp"
       android:layout_below="@id/vol3DividerBar"/>
      <TextView
       android:layout_weight="1"
       android:id="@+id/vol4DividerBar"
       android:layout_width="fill_parent"
       android:layout_height="wrap_content"
    android:text="The Doctrine and Covenants"
    android:textColor="#000"
    android:background="@drawable/volume_divider"
    android:layout_below="@id/vol3Grid"/>
      <GridView
       android:layout_weight="1"
       android:id="@+id/vol4Grid"
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content"
       android:numColumns="auto_fit"
       android:verticalSpacing="0dp"
       android:horizontalSpacing="0dp"
       android:layout_below="@id/vol4DividerBar"/>
      <TextView
       android:layout_weight="1"
       android:id="@+id/vol5DividerBar"
       android:layout_width="fill_parent"
       android:layout_height="wrap_content"
    android:text="The Pearl of Great Price"
    android:textColor="#000"
    android:background="@drawable/volume_divider"
    android:layout_below="@id/vol4Grid"/>
      <GridView
       android:layout_weight="1"
       android:id="@+id/vol5Grid"
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content"
       android:numColumns="auto_fit"
       android:verticalSpacing="0dp"
       android:horizontalSpacing="0dp"
       android:layout_below="@id/vol5DividerBar"/>
  </RelativeLayout>
</ScrollView>
</RelativeLayout>

Thanks

A: 

set both

android:layout_width="wrap_content"
android:layout_height="wrap_content"

tag in All Gridview.

Praveen Chandrasekaran
A: 

I have the same issue. Setting layout_width and height to "wrap_content" does not change anything, neither does height to 0dip and weight to 1. Have you found a solution to your problem or does anyone have one ? Thanks

Axel
A: 

I don't know whether this works, but have you tried setting the layout height to equal the measured height in code?

OhHiThere
A: 

Hi, Why dont you use linear layout

Siddhartho