2009-06-17 4 views
2

У меня есть Activity, который отображает 5 GridViews. Каждый из этих GridViews делится на TextView с фоном, который охватывает ширину экрана. GridViews представляют собой объем книг, и каждый элемент в сетке представляет собой Button, представляющий книгу в томе.Несколько андроид GridViews не будут wrap_content

Все GridViews и TextViews сидят внутри RelativeLayout. В некоторых томах есть много книг и других лишь немногие, поэтому я пытался получить отдельные виды сетки до wrap_content и занял все пространство, необходимое им, чтобы показать все свои книги, но не повезло. View равномерно делит пространство на каждый из GridViews, скрывая большую часть книг. У меня есть мой xml-макет ниже. Может ли кто-нибудь сказать мне, как я могу это сделать?

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

ответ

-1

набор как

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

тег Все Gridview.

1

Попробуйте присвоить GridView Weight = 0.5. Я столкнулся с такой же ситуацией несколько дней назад. Для меня очень простое изменение в макете. Просто добавьте два пустых представления слева и справа от моего GridView с весом = 1 и присвойте 0,5 весу GridView. Например.

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

`

Смежные вопросы