android – 如何强制GridView使用整个屏幕(无论显示大小)?

前端之家收集整理的这篇文章主要介绍了android – 如何强制GridView使用整个屏幕(无论显示大小)?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有以下布局文件,后面有一个GridView和一个 ImageView作为背景.
<?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>

这是我用于网格的每个“单元格”中的实际项目的布局:

<?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>

我现在在设备上看到以下内容

有没有办法让GridView中的每个项目更大,所以它适合屏幕的大小,我没有在显示底部未使用的空白区域?

这在模拟器上工作正常,但在设备上屏幕分辨率更高,因此在底部获得空白区域.

非常感谢

解决方法

@H_301_19@ 不是自动的.

特别是,您的单元格是文本. Android并没有完全准备好猜测文本应该达到多大的目标,特别是考虑到自动换行之后.

GridView的要点是在显示底部有“未使用的空白区域”,如果您没有足够的数据来填充屏幕,那么它可以灵活地处理多个屏幕尺寸,并且如果有更多屏幕也可以容纳滚动数据.如果您的目标是类似于仪表板模式,请考虑使用DashboardLayout或其他类似的东西.

原文链接:https://www.f2er.com/android/317510.html

猜你在找的Android相关文章