我怎么能强迫一个GridView使用整个屏幕(不考虑显示尺寸的)? [英] How can I force a GridView to use the whole screen (regardless of display size)?

查看:521
本文介绍了我怎么能强迫一个GridView使用整个屏幕(不考虑显示尺寸的)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下布局文件,其中有一个GridView和后面,一个ImageView的作为背景。

I've got the following layout file, which has a GridView and an ImageView behind that as the background.

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="#FFFFFF">
    <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|right"
            android:layout_marginRight="-70dp"
            android:layout_marginBottom="-50dp"
            android:src="@drawable/s_background"/>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                  android:layout_width="fill_parent"
                  android:layout_height="fill_parent">
        <GridView xmlns:android="http://schemas.android.com/apk/res/android"
                  android:id="@+id/gridview"
                  android:layout_width="match_parent"
                  android:layout_height="match_parent"
                  android:columnWidth="90dp"
                  android:numColumns="auto_fit"
                  android:verticalSpacing="10dp"
                  android:horizontalSpacing="10dp"
                  android:stretchMode="columnWidth"
                  android:gravity="center"/>
    </LinearLayout>
</FrameLayout>

和,这是我在网格的每个单元用于实际的项目的布局:

And this is the layout I use for the actual item in each "cell" of the grid :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="match_parent"
              android:layout_height="match_parent">
    <TextView
            android:id="@+id/cardInGrid"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:singleLine="true"
            android:textSize="40sp"
            android:textColor="#660099"
            android:typeface="serif"/>
</LinearLayout>

我看到的那一刻我的设备上执行以下操作:

I'm seeing the following on my device at the moment :

有没有办法让在GridView更大的每一个项目,所以它适合屏幕的大小,我没有在屏幕的底部?

Is there any way of making each item in the GridView larger, so it fits the size of the screen and I don't have un-used white space at the bottom of the display?

这工作正常的模拟器,而是一个设备上的屏幕分辨率较高,因此得到的空白底部。

This works fine on an emulator, but on a device the screen resolution is higher, hence getting the white space at the bottom.

感谢

推荐答案

无法自动识别。

在特定的,你的细胞的文本。 Android是不完全到位猜测文本应为多大来完成你的目标,尤其是一旦你把自动换行考虑。

In particular, your cells are text. Android is not exactly in position to guess how big the text should be to accomplish your aims, particularly once you take word-wrap into account.

的GridView 的一点是要有未使用的空白在屏幕底部的,如果你没有足够的数据来填充屏幕,所以它能够灵活地处理多个屏幕大小和还容纳滚动,如果有更多的数据。如果你瞄准了一个类似于仪表板图形,可以考虑使用 DashboardLayout 或类似的规定。

The point of GridView is to have "un-used white space at the bottom of the display", if you do not have enough data to fill the screen, so that it can flexibly handle multiple screen sizes and also accommodate scrolling if there is more data. If you are aiming for something akin to the dashboard pattern, consider using DashboardLayout or something along those lines.

这篇关于我怎么能强迫一个GridView使用整个屏幕(不考虑显示尺寸的)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆