gpt4 book ai didi

android - 多个 android GridViews 不会 wrap_content

转载 作者:行者123 更新时间:2023-11-29 14:11:57 28 4
gpt4 key购买 nike

我有一个显示 5 个 GridViewsActivity。这些 GridViews 中的每一个都被一个背景横跨屏幕宽度的 TextView 分开。 GridViews 表示一卷书,网格中的每个项目都是一个 Button,表示一卷书中的一本书。

所有 GridViewsTextViews 都位于 RelativeLayout 中。有些卷有很多书,而另一些只有几本书,所以我一直在尝试让各个 GridView 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>

最佳答案

尝试分配 GridView 权重 = 0.5。几天前我遇到了同样的情况。对我来说,布局工作的简单改变。只需在我的 GridView 的左侧和右侧添加两个空 View ,权重 = 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>

`

关于android - 多个 android GridViews 不会 wrap_content,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1008703/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com