2009-06-17 24 views
2

Ich habe eine Activity, die 5 GridViews anzeigt. Jede dieser GridViews ist durch eine TextView mit einem Hintergrund, der die Breite des Bildschirms erstreckt geteilt. Die GridViews repräsentieren ein Volumen von Büchern, und jedes Element im Raster ist ein Button, das ein Buch in einem Band darstellt.Mehrere android GridViews werden nicht wrap_content

Alle GridViews und TextViews sitzen in einem RelativeLayout. Einige Volumes haben viele Bücher und andere nur ein paar, also habe ich versucht, die einzelnen Rasteransichten auf wrap_content zu bringen und den ganzen Platz einzunehmen, den sie brauchen, um all ihre Bücher zu zeigen, aber kein Glück. Der View teilt gleichmäßig den Raum zu jedem der GridViews und versteckt die meisten Bücher. Ich habe mein XML-Layout unten. Kann mir jemand sagen, wie ich das schaffen kann?

<?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> 

Antwort

-1

Satz beid

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

Tag in allen Gridview.

1

Versuchen Sie, indem Sie GridView Weight = 0.5 zuweisen. Ich habe vor ein paar Tagen dieselbe Situation. Eine einfache Änderung im Layout funktioniert für mich. Fügen Sie einfach zwei leere Ansichten links und rechts von GridView mit der Gewichtung = 1 hinzu und weisen Sie GridView eine Gewichtung von 0,5 zu. Z.B.

<LinearLayout 
    android:layout_width="fill_parent" 
    android:gravity="center" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" > 

    <View 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" /> 

    <GridView 
     android:id="@+id/myGridView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="0.5" 
     android:numColumns="2" 
     android:scrollbars="none" 
     android:verticalSpacing="10dp" > 
    </GridView> 

    <View 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" /> 
</LinearLayout> 

`