【问题标题】:Adjust gridview between two views within a layout in android在android中的布局中调整两个视图之间的gridview
【发布时间】:2012-12-07 16:01:43
【问题描述】:

在我的应用程序中,我有一个包含LinearLayout--> TopGridView--> Middleset of views which should be aligned to the bottom 的布局。

1. gridview 内容不多时的布局

2。增加网格视图内容时的布局

3.当 Gridview 内容非常大时,布局应该如何显示

目前我的网格视图正在扩展,当其中的内容增加时,较低级别的内容在屏幕中不可见。

我不想为网格视图分配特定的高度,因为它在不同尺寸的屏幕中看起来很奇怪。

Is there any way that the gridview expands only upto the bottom views?我的父布局是LinearLayout。我已经尝试过使用相对布局,但它不起作用。

【问题讨论】:

    标签: android android-layout gridview alignment android-linearlayout


    【解决方案1】:

    我也遇到了同样的问题,通过修改相应的xml找到了解决方案,如下所示:

    1. 使用RelativeLayout 作为父布局。
    2. 将标题内容放在RelativeLayout
    3. 对动态变化的 GridView 使用 ScrollView
    4. 将页脚布局放在ScrollView 之后

    如下图:

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
       android:layout_width="fill_parent"
       android:layout_height="fill_parent" >
     <TextView
        android:id="@+id/txtTextView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"/>
      <ScrollView
        android:id="@+id/scro1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_below="@id/txtTextView" >
      <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
      <GridView
        android:id="@+id/scro1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"/>
      </LinearLayout>
      </ScrollView>
      </RelativeLayout>
    

    ScrollView 中的android:layout_below 属性有所不同。

    【讨论】:

    • GridView 会有自己的滚动条,因此在滚动条中包含 GridView 毫无意义。
    • 我尝试使用gridview inside a scrollview,但没有成功。 :(
    • 您是否尝试过使用页脚布局?当我尝试它时,我将滚动视图扩展到屏幕底部,页脚布局根本不可见。
    • 在我的情况下,当gridview中的内容较少时它工作正常,但是当它开始增加时,较低的视图开始向下移动,最终从布局中消失。由于这些视图未绑定在滚动视图中,因此它们不再可见
    • 好的,我实际上必须搜索它......最后你是否从我的答案中找到解决方案......??