android - GridView 的项目之间的空间

标签 android gridview space

我在我的代码中使用了 GridView。我有空间问题。 这是我的问题:

enter image description here

当文本很短时没问题,但问题是什么时候更长。 我想得到这个:

enter image description here

这是我的 GridView:

<GridView
            android:id="@+id/list"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_margin="5dp"
            android:layout_weight="1"
            android:divider="@color/transparente"
            android:horizontalSpacing="4dp"
            android:longClickable="true"
            android:numColumns="2"
            android:scrollbars="none"
            android:verticalSpacing="4dp" >
        </GridView>

这是 GridView 元素的 xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="5dp"
    android:gravity="center_vertical"
    android:paddingLeft="5dp" >

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:paddingBottom="5dp"
        android:paddingTop="2dp" >

        <TextView
            android:id="@+id/textView_title_name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Text text text text text text"
            android:textColor="@color/blanco"
            android:textSize="@dimen/titulos" />

        <TextView
            android:id="@+id/textView_alarm_time"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Text text text text text text"
            android:textColor="@color/blanco"
            android:textSize="@dimen/contenido" />

        <TextView
            android:id="@+id/textView_alarm_days"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Text text text text text text"
            android:textColor="@color/blanco"
            android:textSize="@dimen/contenido" />
    </LinearLayout>

</LinearLayout>

我尝试使用 android: stretchMode = "spacingWidth", "columnWidth"和 android: verticalSpacing = "4DP" ... 但没有成功

我搜索了答案,但找不到任何帮助我的东西

感谢任何帮助

感谢和问候

最佳答案

您必须声明真正的最大尺寸。在根布局中设置任何参数都无济于事。您应该在每个子元素中单独设置它。 例如,这是我的代码,请查看这两个子元素,它们具有最大可能的高度和宽度。我认为设置宽度并不重要,但我可能错了。但是无论如何都必须设置高度大小。请检查一下并在您的项目中尝试。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:orientation="vertical"
    android:gravity="center"
    android:layout_height="wrap_content">

    <ImageView
        android:id="@+id/image"
        android:layout_width="150dp"
        android:layout_height="200dp"
        android:src="@drawable/stub"
        android:scaleType="centerCrop" />

    <TextView
        android:id="@+id/text"
        android:layout_width="wrap_content"
        android:layout_height="80dp"
        android:layout_gravity="center_horizontal|center_vertical"
        android:textSize="20dip"
        android:ellipsize="end"
        android:visibility="visible"
        android:text="text" />
</LinearLayout>

关于android - GridView 的项目之间的空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19134501/

相关文章:

java - 为 Fragment 中的更多 editTexts 设置 OnFocusChangeListener

android - Gitlab CI gradle 依赖缓存

c# - e.Row.findcontrol() 在数据绑定(bind)后返回 null 但所有数据绑定(bind)字段都正常工作

c# - 根据字符格式化字符串

android - 在 Android 应用程序中使用 X509 证书

android - Ormlite 数据库助手 - onCreate() 未调用

gridview - flutter - 在 gridview 上换行时如何设置宽度?

android - Gridview 元素对齐

java - 如何向现有字符串添加空格?

html - BODY 之前的空间?