如何强制 GridView 使用整个屏幕(无论显示大小如何)? [英] How can I force a GridView to use the whole screen (regardless of display size)?

查看:20
本文介绍了如何强制 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天全站免登陆