Несколько андроид GridViews не будут - PullRequest
2 голосов
/ 17 июня 2009

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

Все 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>

Ответы [ 2 ]

1 голос
/ 24 апреля 2013

Попробуйте назначить GridView Weight = 0.5. Я столкнулся с такой же ситуацией несколько дней назад. Простое изменение в Layout работает для меня. Просто добавьте два пустых представления слева и справа от моего GridView с weight = 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>

`

0 голосов
/ 27 февраля 2010

установить оба

android:layout_width="wrap_content"
android:layout_height="wrap_content"
Тег

в All Gridview.

...